I was actually looking for a rolling year so I jsut changed the where clause on the date to this.
Code:
select [Passenger ID],count(*) as [Total flights],max(FlightDate) as [Last Flight Date] from PassengerFlights p inner join Flights f on p.FlightID=f.FlightID where FlightDate >= dateadd(day,-365,GetDate()) group by [Passenger ID] )
Leave a comment: