1
yejinmo 2017-08-08 21:52:43 +08:00
结果应该是
1 3 2 5 3 3 吧 |
2
xxoxx 2017-08-08 21:54:16 +08:00
目测了一下,结果应该是
1 3 2 5 3 2 |
3
yejinmo 2017-08-08 21:54:17 +08:00
select a, count(a) from
( (select a from test union all select b from test) as temp ) group by a; |
5
yuanfnadi OP 重复的不算
应该是 13 24 32 33 是手抖了 |
6
akira 2017-08-08 22:45:08 +08:00
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 |
7
zeraba 2017-08-08 23:04:31 +08:00 via Android
就按照你的思路 把 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 |
8
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; |