Select To_char(x.Fld004, 'dd/mm/yyyy hh24'),
max(decode(fld008,1,count(1),null)) as aa,
max(decode(fld008,2,count(1),null)) as bb
From Pti020 x, Pti042 y
Where x.Fld008 = y.Fld001
And x.fld004 < trunc(sysdate-1)
and x.fld004 > trunc(sysdate-2)
Group By To_char(x.Fld004, 'dd/mm/yyyy hh24')
order by To_char(x.Fld004, 'dd/mm/yyyy hh24'), aa, bb;
为什么我在执行时遇到00937错误?怎么解决?
答案 0 :(得分:0)
您通常不会嵌套聚合函数。也许您打算更像这样的查询:
select To_char(x.Fld004, 'dd/mm/yyyy hh24'),
sum(case when fld008 = 1 then 1 else 0 end) as aa,
sum(case when fld008 = 2 then 1 else 0 end) as bb
from Pti020 x join
Pti042 y
on x.Fld008 = y.Fld001
where x.fld004 < trunc(sysdate-1) and
x.fld004 > trunc(sysdate-2)
group By to_char(x.Fld004, 'dd/mm/yyyy hh24')
order by To_char(x.Fld004, 'dd/mm/yyyy hh24');
以下是更改:
,
被显式JOIN
取代。您应该使用正确的显式JOIN
语法。max()
代替sum()
。aa
删除了bb
和order by
,因为group by
保证第一列是唯一的。