I have a query which needs to group by year.
select distinct emp.id, emp.name, emp.joining_on from employee;
Output:
id ---- name ---- joining_on 1 ----- Tev ----- 8/15/2020 10:30:52
2 ----- Sam ----- 12/26/2017 16:18:44
3----- Karen --- 07/18/2020 08:09:33
4 ----- Cher --- 09/23/2018 10:08:44
Please help me to group by year.
You can use extract() to extract the year from the date:
extract()
select extract(year from joining_on) as yyyy, count(*) from t group by extract(year from joining_on) order by extract(year from joining_on);
1.4m articles
1.4m replys
5 comments
57.0k users