CREATE TABLE `table`
(`source` varchar(20), `eventid` varchar(9), `system` varchar(10),`accountname` varchar(10))
;
INSERT INTO `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')
;
如果我使用查询
SELECT SOURCE,accountname,SYSTEM, count(*)
FROM `table`
WHERE eventid = '528'
GROUP BY SOURCE,accountname
我得到结果
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
我希望结果只显示
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) 将源、帐户名分组为多行,而不是单行,例如 AAUNSWH20。
有人可以帮助制定查询吗?..谢谢