我有一个来自Oracle sql的要求,它将显示来自查询的数据,并输出如下所示: -
查询:
Select a,b,Count(*),0-2,2-4,4-24,24-48,>48
from Table
where id=4
group by a,b,0-2,2-4,4-24,24-48,>48;
id = 4的示例输出,这里假设count为6
Count(*)|0-2|2-4|4-24|24-48|>48|
--------|---|---|----|-----|---|
6 |0 |0 |6 |0 |0 |
注意0-2,2-4,4-24,24-48,> 48是列名
答案 0 :(得分:0)
这只是一堆case
语句:
Select a, b,
(case when Count(*) < 2 then count(*) else 0 end) as "0-1",
(case when count(*) >= 2 and count(*) < 4 then count(*) else 0 end) as "2-3",
. . .
from Table
where id = 4
group by a, b;
注意:between
在SQL中是包含的。我假设你不想要计算&#34; 2&#34;出现在两列中。