SELECT CASE WHEN dif IN ('c', 'd') THEN 'cd' ELSE dif END AS dif,
COUNT(*)
FROM table_name
GROUP BY
CASE WHEN dif IN ('c', 'd') THEN 'cd' ELSE dif END;
其中,对于样本数据:
CREATE TABLE table_name (dif) AS
SELECT 'a' FROM DUAL CONNECT BY LEVEL <= 5 UNION ALL
SELECT 'b' FROM DUAL CONNECT BY LEVEL <= 3 UNION ALL
SELECT 'c' FROM DUAL CONNECT BY LEVEL <= 6 UNION ALL
SELECT 'd' FROM DUAL CONNECT BY LEVEL <= 7;
2条答案
按热度按时间f0brbegy1#
使用
CASE
表达式:其中,对于样本数据:
输出:
| DIF| COUNT(*)|
| - -----|- -----|
| B| 3|
| 一种|5个|
| 光盘|十三个|
fiddle
jv2fixgn2#
Case应该可以
返回
使用Case定义一个新的变量来分组,如下所示:
返回
注意:这是用postgresql而不是oracle完成的,但应该是可以理解的