SQL Server 2008 again. I have a primary key pt_id and a datetime column order_dts for each id. I want to count the number of keys in each year from 1996-2008 and return eight results – a count for each year. For a single year
SELECT COUNT pm.pt_id AS '1996'
FROM dm.medications pm
WHERE (pm.order_dts BETWEEN '1/1/1996' and '12/31/1996')
works, but how I can I do all of the years without having to do something ridiculous like eight different queries?
Thank you!
If you want it all in one row, you can do: