I have a query where I want to display the owner and the number of times they took the car, bus or train to work. so the table should look like this;
Owner | Car | Bus | Train
-------------------------
Joe | 1 | 2 | 4
This is my query;
Select owner, vehicle
From MyTable
INNER JOIN(select
count(case when vehicle = 'Car' then 1 else 0 end) AS [Car],
count(case when vehicle = 'Bus' then 1 else 0 end) AS [Bus],
count(case when vehicle = 'Train' then 1 else 0 end) AS [Train]
from dbo.MyTable
where
YEAR([CreatedOn]) = 2015
group by
vehicle)
Im getting an incorrect syntax error