我有以下查询返回我正在寻找的结果,但事实上我无法分组工作:
select EXTRACT(month from datetime_insert) m,
EXTRACT(year from datetime_insert) y
from tst_result_main
order by datetime_insert
返回以下内容:
m y
1 2006
1 2006
2 2006
2 2006
2 2007
2 2007
我正在寻找的结果:
m y
1 2006
2 2006
2 2007
我试过以下哪个引发错误:
select EXTRACT(month from datetime_insert) m,
EXTRACT(year from datetime_insert) y
from tst_result_main
order by datetime_insert group by y, m
错误:
ORA-00933:SQL命令未正确结束 00933. 00000 - " SQL命令未正确结束" *原因:
*动作:行错误:7列:136
任何帮助将不胜感激
答案 0 :(得分:6)
您是否尝试过类似DISTINCT值的内容:
select DISTINCT
EXTRACT(month from datetime_insert) m
, EXTRACT(year from datetime_insert) y
from tst_result_main
答案 1 :(得分:2)
如果没有聚合功能,你应该使用distinct子句而不是分组
select DISTINCT
EXTRACT(month from datetime_insert) m
, EXTRACT(year from datetime_insert) y
from tst_result_main
order by y, m
答案 2 :(得分:0)
试试这个:
select EXTRACT(month from datetime_insert) m, EXTRACT(year from datetime_insert) y
from tst_result_main
group by EXTRACT(year from datetime_insert), EXTRACT(month from datetime_insert)
order by y,m;
别名不能用于group by
表达式。