SELECT distinct denomination,
(SELECT count(com) from security where denomination = 200),
(SELECT count(com) from security where denomination = 50),
(SELECT count(com) from security where denomination = 1000),
(SELECT count(com) from security where denomination = 100) from security;
denomination | ?column? | ?column? | ?column? | ?column?
--------------+----------+----------+----------+----------
200 | 1 | 2 | 1 | 2
50 | 1 | 2 | 1 | 2
100 | 1 | 2 | 1 | 2
1000 | 1 | 2 | 1 | 2
以上代码打印上述结果。那不是我想要的。我如何写出每个面额值的com计数,以便它出现在各自面额附近的单独列中?我希望它看起来像这样:
denomination | ?column? |
--------------+----------+
200 | 1 |
50 | 2 |
100 | 2 |
1000 | 1 |
我确定答案很简单,我只是无法理解它。
答案 0 :(得分:2)
SELECT denomination, count(com)
FROM security
WHERE denomination IN (200, 50, 1000, 100)
GROUP BY denomination;