-2

我有一个名为“数字”的表,有 4 列(id、N1、N2、N3),如下所示:

id = 1,2 3, 4


N1 = 22 , 14 , 13 , 15

N2 = 13 , 11 , 80 , 11

N3 = 11 , 22 , 47 , 23

我可以计算此表中各个数字的总频率吗? (11 = 3) ** (22=2)ETC..

对于一列,我的查询是:

"SELECT N1, COUNT(*) as Frequency FROM number GROUP BY n1 order by count(*) desc"

感谢您的帮助

4

1 回答 1

0

尝试这个:

SELECT t.num, COUNT(t.num)
FROM (SELECT N1 AS num FROM number
      UNION ALL
      SELECT N2 AS num FROM number
      UNION ALL
      SELECT N3 AS num FROM number) AS t
GROUP BY t.num
ORDER BY COUNT(t.num) desc;

小提琴演示

UNION 运算符

于 2013-08-16T08:26:39.973 回答