SELECT a, SUM(`t`) `count` FROM ( SELECT a, COUNT(a) `t` FROM test GROUP BY a UNION SELECT b, COUNT(b) FROM test WHERE a<>b GROUP BY b )tt GROUP BY a
zeraba
2017-08-08 23:04:31 +08:00
就按照你的思路 把 a b 先并到一起 参考 3 楼 一样的随便取一个 最后 group by 伪代码 select case when a = b then a else a end hebing from test union select case when a <> b then b end hebing
SuperMild
2017-08-13 13:05:27 +08:00
select a, sum(num) as 'count' from (select a, count(a) as num from AandB where a <> b group by a union all select b, count(b) from AandB where a <> b group by b union all select b, count(b) from AandB where a = b group by b) group by a;
第 1 页 / 共 1 页
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。