表有两列
a b
1 2
1 3
2 3
2 1
2 2
现在要求出所有的数字一共出出现了几列
结果应该是
1 3
2 4
3 3
用数据库写我想到的方法是分别求出两列个数,相加以后减去相同的个数
a b
1 2
1 3
2 3
2 1
2 2
现在要求出所有的数字一共出出现了几列
结果应该是
1 3
2 4
3 3
用数据库写我想到的方法是分别求出两列个数,相加以后减去相同的个数
|
yejinmoAug 8, 2017
1
结果应该是
1 3 2 5 3 3 吧 |
|
xxoxxAug 8, 2017
2
目测了一下,结果应该是
1 3 2 5 3 2 |
|
yejinmoAug 8, 2017
3
select a, count(a) from
( (select a from test union all select b from test) as temp ) group by a; |
|
5
重复的不算
应该是 13 24 32 33 是手抖了 |
|
akiraAug 8, 2017
6
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 |
|
zerabaAug 8, 2017 via Android
7
就按照你的思路 把 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 |
|
SuperMildAug 13, 2017
8
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; |