[英]Oracle SQL query for Year
select null link, CRIME_DATE label, SUM(CRIME_NO) value1
from "C3348242"."CRIME"
group by CRIME_DATE
order by CRIME_DATE DESC
I currently have this SQL query but it is not giving me the results that I desire. 我目前有这个SQL查询,但没有给我想要的结果。 I want to select all the crimes that occurred in a certain year and order them by the different years for example all the crime 2013, 2014 etc. I want to get the year from the Crime_date column which is stored as DATE datatype. 我想选择某年发生的所有犯罪,并按不同年份对它们进行排序,例如所有2013、2014等犯罪。我想从存储为DATE数据类型的Crime_date列中获取年份。 Can anyone help? 有人可以帮忙吗?
Thanks 谢谢
You can get the year using extract
: 您可以使用extract
获取年份:
select extract(year from CRIME_DATE) year
, null link
, CRIME_DATE label
, SUM(CRIME_NO) value1
from "C3348242"."CRIME"
group
by extract(year from CRIME_DATE)
, CRIME_DATE
order
by extract(year from CRIME_DATE) desc
, CRIME_DATE DESC
You could also use to_char(crime_date, 'yyyy')
您也可以使用to_char(crime_date, 'yyyy')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.