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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -