2016-08-30 125 views

回答

2

您可以使用case聲明:

select (case when field = 1 then '1' else 'All Other Values' end) as grp, 
     count(*) 
from t 
group by (case when field = 1 then '1' else 'All Other Values' end); 
0

儘管戈登的回答是比較正確的,你也可以使用甲骨文解碼:

SELECT DECODE(a.col, 1, 'first', 'other'), COUNT(*) 
FROM atable a 
GROUP BY DECODE(a.col, 1, 'first', 'other'); 
+0

我建議'decode'應在案件勸阻像這個。 「case」表達式的編寫,閱讀和維護要容易得多。在'case'陳述出臺之前,'decode'在過去有其目的。 – mathguy