SELECT DATEADD(MONTH,DATEDIFF(MONTH,0,[start_date]),0) As TripMonth,
COUNT(id) As 'NumTrips',
CASE WHEN DATEDIFF(DAY, Start_Date, End_Date) > 0 THEN 1 ELSE 0 END
) As 'NumTrips>Day'
GROUP BY DATEADD(MONTH,DATEDIFF(MONTH,0,[start_date]),0)
Get contiguous subset from given N numbers using less numbers of loop
By : user3583504
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further You can't reduce the time complexity as you want to generate all subarrays. However, you can make use of range function in PHP to reduce the nested loops to 2. Note that this doesn't technically reduce the nested length to 2, see range function code but the code looks more idiomatic.