本帖最后由 zhangyu4849467 于 2012-5-14 14:57 编辑
〇〇 发表于 2012-5-14 13:16
错误提示信息?
ORA-00905: missing keyword
主要是使用group by grouping sets ,就报 缺失关键字,
这个是全部的sql , 帮我看下 啊 , 谢谢
select
order_time,
case
when g1 = 0 then to_char(order_time,'yyyy-mm-dd hh24:mi:ss')
when g1 = 1 and g2 = 1 and g3 = 1 and g4 = 0 and g5 = 0 and g6 = 1 and g7 = 1 then
case
when shift = 1 then '08~17班次'
when shift = 2 then '17~02班次'
when shift = 3 then '02~08班次'
else null
end
when g1 = 1 and g2 = 3 and g3 = 3 and g4 = 1 and g5 = 0 and g6 = 1 and g7 = 1 then '24小时总结'
else null
end as show_time,tem,pulse,breathe,blood_pressure,pulse_oxygen,in_name,in_quantity,route,out_name,out_quantity,groupid,disposalcontent,in_type,out_type from (
select
case
when grouping(row_num) = 0
then max(order_time)
when grouping(row_num) = 1 and grouping_id(shift_date,shift,in_type) = 0 and grouping_id(shift_date,shift,out_type) = 1 and grouping_id(shift_date,shift) = 0 and grouping(shift_date) = 0 and grouping_id(shift_date,in_type) = 0 and grouping_id(shift_date,out_type) = 1 and in_type is not null then
case
when shift = 1
then shift_date + 17/24 + 1/(24*60*60)
when shift = 2
then (shift_date + 1) + 1/12 + 1/(24*60*60)
else (shift_date + 1) + 1/3 + 1/(24*60*60)
end
when grouping(row_num) = 1 and grouping_id(shift_date,shift,in_type) = 1 and grouping_id(shift_date,shift,out_type) = 0 and grouping_id(shift_date,shift) = 0 and grouping(shift_date) = 0 and grouping_id(shift_date,in_type) = 1 and grouping_id(shift_date,out_type) = 0 and out_type is not null then
case
when shift = 1
then shift_date + 17/24 + 1/(24*60*60)
when shift = 2
then (shift_date + 1) + 1/12 + 1/(24*60*60)
else (shift_date + 1) + 1/3 + 1/(24*60*60)
end
when grouping(row_num) = 1 and grouping_id(shift_date,shift,in_type) = 1 and grouping_id(shift_date,shift,out_type) = 1 and grouping_id(shift_date,shift) = 0 and grouping(shift_date) = 0 and grouping_id(shift_date,in_type) = 1 and grouping_id(shift_date,out_type) = 1 then
case
when shift = 1
then shift_date + 17/24 + 1/(24*60*60)
when shift = 2
then (shift_date + 1) + 1/12 + 1/(24*60*60)
else (shift_date + 1) + 1/3 + 1/(24*60*60)
end
when grouping(row_num) = 1 and grouping_id(shift_date,shift,in_type) = 3 and grouping_id(shift_date,shift,out_type) = 3 and grouping_id(shift_date,shift) = 1 and grouping(shift_date) = 0 and grouping_id(shift_date,in_type) = 1 and grouping_id(shift_date,out_type) = 1
then (shift_date + 1) + 1/3 + 1/(24*60*60)
when grouping(row_num) = 1 and grouping_id(shift_date,shift,in_type) = 2 and grouping_id(shift_date,shift,out_type) = 3 and grouping_id(shift_date,shift) = 1 and grouping(shift_date) = 0 and grouping_id(shift_date,in_type) = 0 and grouping_id(shift_date,out_type) = 1 and in_type is not null
then (shift_date + 1) + 1/3 + 1/(24*60*60)
when grouping(row_num) = 1 and grouping_id(shift_date,shift,in_type) = 3 and grouping_id(shift_date,shift,out_type) = 2 and grouping_id(shift_date,shift) = 1 and grouping(shift_date) = 0 and grouping_id(shift_date,in_type) = 1 and grouping_id(shift_date,out_type) = 0 and out_type is not null
then (shift_date + 1) + 1/3 + 1/(24*60*60)
else null
end as order_time,decode(grouping(row_num),0,max(tem),null) as tem,decode(grouping(row_num),0,max(pulse),null) as pulse,
decode(grouping(row_num),0,max(breathe),null) as breathe,decode(grouping(row_num),0,max(blood_pressure),null) as blood_pressure,decode(grouping(row_num),0,max(pulse_oxygen),null) as pulse_oxygen,
case
when grouping(row_num) = 0
then max(in_name)
when grouping(row_num) = 1 and grouping_id(shift_date,shift,in_type) = 0 and grouping_id(shift_date,shift,out_type) = 1 and grouping_id(shift_date,shift) = 0 and grouping(shift_date) = 0 and grouping_id(shift_date,in_type) = 0 and grouping_id(shift_date,out_type) = 1 and in_type is not null
then in_type
when grouping(row_num) = 1 and grouping_id(shift_date,shift,in_type) = 1 and grouping_id(shift_date,shift,out_type) = 1 and grouping_id(shift_date,shift) = 0 and grouping(shift_date) = 0 and grouping_id(shift_date,in_type) = 1 and grouping_id(shift_date,out_type) = 1
then '入量小结'
when grouping(row_num) = 1 and grouping_id(shift_date,shift,in_type) = 3 and grouping_id(shift_date,shift,out_type) = 3 and grouping_id(shift_date,shift) = 1 and grouping(shift_date) = 0 and grouping_id(shift_date,in_type) = 1 and grouping_id(shift_date,out_type) = 1
then '总入量'
when grouping(row_num) = 1 and grouping_id(shift_date,shift,in_type) = 2 and grouping_id(shift_date,shift,out_type) = 3 and grouping_id(shift_date,shift) = 1 and grouping(shift_date) = 0 and grouping_id(shift_date,in_type) = 0 and grouping_id(shift_date,out_type) = 1 and in_type is not null
then in_type
else null
end as in_name,sum(in_quantity) as in_quantity,decode(grouping(row_num),0,max(route),null) as route,
case
when grouping(row_num) = 0
then max(out_name)
when grouping(row_num) = 1 and grouping_id(shift_date,shift,in_type) = 1 and grouping_id(shift_date,shift,out_type) = 0 and grouping_id(shift_date,shift) = 0 and grouping(shift_date) = 0 and grouping_id(shift_date,in_type) = 1 and grouping_id(shift_date,out_type) = 0 and out_type is not null
then out_type
--
when grouping(row_num) = 1 and grouping_id(shift_date,shift,in_type) = 1 and grouping_id(shift_date,shift,out_type) = 1 and grouping_id(shift_date,shift) = 0 and grouping(shift_date) = 0 and grouping_id(shift_date,in_type) = 1 and grouping_id(shift_date,out_type) = 1
then '出量小结'
when grouping(row_num) = 1 and grouping_id(shift_date,shift,in_type) = 3 and grouping_id(shift_date,shift,out_type) = 3 and grouping_id(shift_date,shift) = 1 and grouping(shift_date) = 0 and grouping_id(shift_date,in_type) = 1 and grouping_id(shift_date,out_type) = 1
then '总出量'
when grouping(row_num) = 1 and grouping_id(shift_date,shift,in_type) = 3 and grouping_id(shift_date,shift,out_type) = 2 and grouping_id(shift_date,shift) = 1 and grouping(shift_date) = 0 and grouping_id(shift_date,in_type) = 1 and grouping_id(shift_date,out_type) = 0 and out_type is not null
then out_type
else null
end as out_name,sum(out_quantity) as out_quantity,decode(grouping(row_num),0,max(groupid),null) as groupid,decode(grouping(row_num),0,max(disposalcontent),null) as disposalcontent,
grouping(row_num) g1,grouping_id(shift_date,shift,in_type) g2,grouping_id(shift_date,shift,out_type) g3,grouping_id(shift_date,shift) g4,grouping(shift_date) g5,
grouping_id(shift_date,in_type) g6,grouping_id(shift_date,out_type) g7,shift,shift_date,max(in_type) as in_type,max(out_type) as out_type from(
select
rownum as row_num,order_time,decode(tem,lag(tem,1,null) over(partition by order_time order by order_time),null,tem) as tem,
decode(pulse,lag(pulse,1,null) over(partition by order_time order by order_time),null,pulse) as pulse,
decode(breathe,lag(breathe,1,null) over(partition by order_time order by order_time),null,breathe) as breathe,
decode(blood_pressure,lag(blood_pressure,1,null) over(partition by order_time order by order_time),null,blood_pressure) as blood_pressure,
decode(pulse_oxygen,lag(pulse_oxygen,1,null) over(partition by order_time order by order_time),null,pulse_oxygen) as pulse_oxygen,
in_name,in_quantity,in_type,in_no,route,out_name,out_quantity,out_type,out_no,groupid,
decode(disposalcontent,lag(disposalcontent,1,null) over(partition by order_time order by order_time),null,disposalcontent) as disposalcontent,
case
when (to_char(order_time,'hh24') >= 02 and to_char(order_time,'hh24') = 08 and to_char(order_time,'hh24') = to_date('2012-05-12 00:00:00','yyyy-mm-dd hh24:mi:ss')
and inoutdate = to_date('2012-5-12 00:00:00','yyyy-mm-dd hh24:mi:ss')
and plantime = to_date('2012-5-12 00:00:00','yyyy-mm-dd hh24:mi:ss')
and disposaltime <= to_date('2012-5-12 23:59:59','yyyy-mm-dd hh24:mi:ss')) d
on t.patient_id = d.admissionid and t.series = d.series and t.plantime = d.disposaltime) tp
on in_out.admissionid = tp.p_id and in_out.series = tp.series and in_out.inoutdate = tp.order_time))
group by grouping sets((row_num),(shift_date,shift,in_type),(shift_date,shift,out_type),(shift_date,shift),(shift_date),(shift_date,in_type),(shift_date,out_type)))
where order_time is not null and (in_quantity is not null or out_quantity is not null or tem is not null or pulse is not null or breathe is not null or blood_pressure is not null or pulse_oxygen is not null or disposalcontent is not null)
order by 1,tem,pulse,breathe,blood_pressure,pulse_oxygen,disposalcontent,g4,g5,g3 desc,g6 desc
|