【发布时间】:2015-08-06 23:39:44
【问题描述】:
select
create_date
,resolved_date
,to_char(create_date, 'YYYY') as year_create
,to_char(create_date, 'MM') as month_create
,to_char(create_date, 'WW') as week_create
,to_char(create_date,'Q') as quarter_create
,to_char(resolved_date, 'YYYY') as year_resolved
,to_char(resolved_date, 'MM') as month_resolved
,to_char(resolved_date, 'WW') as week_resolved
,to_char(resolved_date,'Q') as quarter_resolved
,item
,site
,status
,contact_time
,impact_label
from mytable
where
create_date between to_date('2013/03/01','YYYY/MM/DD') and to_date('2015/08/06','YYYY/MM/DD')
and case item
when '1' then 'a'
when '2' then 'b'
when '3' then 'c'
else null
end
group by
create_date
,resolved_date
,to_char(create_date, 'YYYY')
,to_char(create_date, 'MM')
,to_char(create_date, 'WW')
,to_char(create_date,'Q')
,to_char(resolved_date, 'YYYY')
,to_char(resolved_date, 'MM')
,to_char(resolved_date, 'WW')
,to_char(resolved_date,'Q')
,item
,site
,status
,contact_time
,impact_label
order by item, site, create_date;
谁能帮我找出错误
无效的关系运算符
(它在一行一行中表示)。我没有看到我可能遗漏的地方><= ?
【问题讨论】:
-
首先,你为什么有一个
group by子句?您似乎没有进行任何聚合。其次,在您的where子句中,您有一个case语句,但您没有将该语句的结果与任何内容进行比较。我不知道你想用case声明来完成什么,所以很难猜出你的意图。 -
1.我认为 group by 在任何情况下都是必要的,如果没有,我可以尝试将其删除。 2.在我的case语句中,我试图为我的item列生成不同的结果,所以如果它的结果为1 - >它将显示a ...这实际上不是我的case语句,我只是编造的一个例子。谢谢!
-
A
group by仅在您希望将行分组并聚合数据时使用。听起来您可以删除group by。如果您希望case语句更改显示的内容,您希望它在select子句中作为投影中的附加列,而不是在where子句中。 -
techonthenet.com/sql/group_by.php 不是聚合函数所必需的分组方式吗?
-
没有。当您的查询在某些列上包含聚合函数时,您使用
group by。否则,对行进行分组是没有意义的。您可以包含不带聚合函数的group by。它只是无缘无故地减慢查询速度,并使支持变得更加痛苦。
标签: oracle operator-keyword relational