Mysql group by query with where condition -
i have table folowing structure
create table `abc` ( `sno` int(11) not null,<br> `id1` int(11) unsigned not null default '0', `id2` int(11) unsigned not null default '0', `type` char(1) not null default '', `time` datetime not null default '0000-00-00 00:00:00', primary key (`sno`), unique key `ind1` (`id1`,`id2`), key `receiver` (`id2`) ) i want id2's grouped id1's have type 'a' .if no id1 id2 combination have type 'a' other id1 id2 combinations. have used following query-:
select id1, group_concat( id2 ) , group_concat( type ) contacts time > '2017-08-11 00:00:00' group id1 now gives me type group concatenated string have operate upon id1,id2 combinations type 'a'.
output-:
id1 | group_concat(id2) | group_concat(type) | 144111 | 556,3577,254389 | a,i,i | can there way done mysql without need of further group_concatenated string?
would using temporary tables better way?
Comments
Post a Comment