mysql - Extract groups with multiple rows -


create table `table`     (`source` varchar(20), `eventid` varchar(9), `system` varchar(10),`accountname` varchar(10))  ;  insert `table`     (`source`, `eventid`, `system` ,`accountname`) values     ('uatapp', '528', 'bxw','jbb'),     ('uatapp', '528', 'bxw','jbc'),     ('nxapp', '530', 'gg','ff'),     ('aaunswh20', '528', 'ccd','ff'),     ('172.1.12.3', '528','vv','ff'),            ('172.1.12.3', '528', 'vv', 'ff'),     ('172.1.12.3', '528','vv','ff3') ; 

if use query

select   source,accountname,system, count(*)     `table`    eventid = '528' group source,accountname 

i result

source  accountname     system  count(*) 172.1.12.3  ff  vv  2 172.1.12.3  ff3     vv  1 aaunswh20   ff  ccd     1 uatapp  jbb     bxw     1 uatapp  jbc     bxw     1 

i result show only

source  accountname     system  count(*) 172.1.12.3  ff  vv  2 172.1.12.3  ff3     vv  1 uatapp  jbb     bxw     1 uatapp  jbc     bxw     1 

(ie) grouping of source,accountname multiple rows , not single row such aaunswh20.

can in formulating query?..thanks

the basic query rejecting 1 shows source , system, doesn't group accountname:

select source, system `table` eventid = '528' group source, system having count(distinct accountname) >= 2; 

the problem is, can't see account names used. can accomplished putting query derived table, join original table, so:

select distinct    t.*    `table` t    inner join (       select source, system       `table`       eventid = '528'       group source, system       having count(distinct accountname) >= 2    ) d on t.source = d.source       , t.system = d.system    t.eventid = '528' ; 

see working in sql fiddle.


Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

C# WinForm - loading screen -