Reputation: 23
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. 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. Can anyone help?
Thanks
Upvotes: 1
Views: 148
Reputation: 156928
You can get the year using 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')
Upvotes: 1