UserId, SRC, DST, Mode, Dist, Year 1,CHN,IND,airplane,200,1990 2,IND,CHN,airplane,200,1991 3,IND,CHN,airplane,200,1992 4,RUS,IND,airplane,200,1990 5,CHN,RUS,airplane,200,1992 6,AUS,PAK,airplane,200,1991
I want to find the total distance traveled by a user in a particular year.
Ex: <Id> <Distance> <year> 1 200 1991 1 600 1993 2 400 1991 2 200 1992
How do I write query for this?
Advertisement
Answer
You need to add holidays.year in group by
clause
select holidays.id, sum(holidays.distance) as totaldistance, holidays.year from holidays group by holidays.id ,holidays.year order by holidays.id ASC