假设有一张table:
first second third
1 1 1
1 1 1
1 2 2
1 1 2
2 3 1
字符串
通过查询:
SELECT first, count(*) AS cnt
FROM table
GROUP BY first
型
我们得到的结果是:
first cnt
1 4
2 1
型
如何计算组内另一列(列)的计数?预期结果:
first cnt aggregated_count_by_second aggregated_count_by_third
1 4 {1: 3, 2: 1} {1: 2, 2: 2}
2 1 {3: 1} {1: 1}
型
数据库版本:10.3.39-MariaDB-0+ deb 10 u1
1条答案
按热度按时间ldfqzlk81#
如果你改变了,请再问一个问题。
对于原来的问题,你可以这样做:
字符串
参见dbfiddle。
第二个快速版本:
型
参见dbfiddle