0
votes

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.

1
Please show us the expected output.Popeye

1 Answers

0
votes

You can use extract() to extract the year from the date:

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);