Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql oracle中pivot的替代方案_Sql_Oracle_Pivot - Fatal编程技术网

Sql oracle中pivot的替代方案

Sql oracle中pivot的替代方案,sql,oracle,pivot,Sql,Oracle,Pivot,我需要根据同一列上的不同条件计算记录数。下面是一个例子。请让我知道如何做到这一点 表中有4列,分别为C1、C2、C3、无天数,数据如下 C1|C2|C3|no_of_days -------------------- A |B |C |7 X |B |C |8 Z |D |E |15 Y |D |E |22 P |D |E |34 Q |R |S |8 我需要以如下格式显示数据 C2|C3|<=7D|8-14D|15-21D|22-27D ------------------------

我需要根据同一列上的不同条件计算记录数。下面是一个例子。请让我知道如何做到这一点

表中有4列,分别为C1、C2、C3、无天数,数据如下

C1|C2|C3|no_of_days
--------------------
A |B |C |7
X |B |C |8
Z |D |E |15
Y |D |E |22
P |D |E |34
Q |R |S |8
我需要以如下格式显示数据

C2|C3|<=7D|8-14D|15-21D|22-27D
------------------------------
B |C |1   |1    |0     |0
D |E |0   |1    |1     |1
R |S |0   |1    |0     |0

C2 | C3 |您按C2和C3分组,并总结出现的情况:

select c2, c3
  , sum( case when no_of_days <= 7 then 1 else 0 end) as dlt8
  , sum( case when no_of_days between 8 and 14 then 1 else 0 end) as d8to14
  , sum( case when no_of_days between 15 and 21 then 1 else 0 end) as d15to21
  , sum( case when no_of_days between 22 and 27 then 1 else 0 end) as d22to27
from mytable
group by c2, c3
order by c2, c3;
选择c2、c3

,求和(如果在天内没有发生),则按C2和C3分组,并总结发生情况:

select c2, c3
  , sum( case when no_of_days <= 7 then 1 else 0 end) as dlt8
  , sum( case when no_of_days between 8 and 14 then 1 else 0 end) as d8to14
  , sum( case when no_of_days between 15 and 21 then 1 else 0 end) as d15to21
  , sum( case when no_of_days between 22 and 27 then 1 else 0 end) as d22to27
from mytable
group by c2, c3
order by c2, c3;
选择c2、c3

,求和(如果在天内没有发生),则按C2和C3分组,并总结发生情况:

select c2, c3
  , sum( case when no_of_days <= 7 then 1 else 0 end) as dlt8
  , sum( case when no_of_days between 8 and 14 then 1 else 0 end) as d8to14
  , sum( case when no_of_days between 15 and 21 then 1 else 0 end) as d15to21
  , sum( case when no_of_days between 22 and 27 then 1 else 0 end) as d22to27
from mytable
group by c2, c3
order by c2, c3;
选择c2、c3

,求和(如果在天内没有发生),则按C2和C3分组,并总结发生情况:

select c2, c3
  , sum( case when no_of_days <= 7 then 1 else 0 end) as dlt8
  , sum( case when no_of_days between 8 and 14 then 1 else 0 end) as d8to14
  , sum( case when no_of_days between 15 and 21 then 1 else 0 end) as d15to21
  , sum( case when no_of_days between 22 and 27 then 1 else 0 end) as d22to27
from mytable
group by c2, c3
order by c2, c3;
选择c2、c3
,总和(无天数时的情况)