If condition with group_concat in mysql -


i have table has 2 columns empid & depid. table not have primary key. below data of table.

+-------+-------+ | empid | depid | +-------+-------+ |     1 |     1 | |     1 |     2 | |     1 |     3 | |     1 |     4 | |     2 |     1 | |     2 |     2 | |     2 |     3 | |     2 |     4 | +-------+-------+ 

now select depids employee wrote below query.

select empid, group_concat(depid separator ':') emp group empid; 

it giving me expected output.

+-------+-----------------------------------+ | empid | group_concat(depid separator ':') | +-------+-----------------------------------+ |     1 | 1:2:3:4                           | |     2 | 1:2:3:4                           | +-------+-----------------------------------+ 

now want select depids greater 2. how can use if group_concat?

try below :

select empid, group_concat(if(depid>2,depid,null) separator ':') emp group empid;


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -