2013-02-26 85 views
0

另一個簡單的問題,我沒有得到解決方法的線索,並想知道你是否可以提供幫助。我需要總共140萬行數據,每行有一定數量的PitchNights,行1 = 2,行2 = 26,行14000 = 3等,所以如果我只有這3行,總數將是31。我需要在2組日期之間總共有所有Pitch之夜。我嘗試了按功能分組,但沒有奏效。來自DATEDIFF的總計

SELECT 
    Bookings.BookingNumber 
    ,Bookings.ArrivalDate 
    ,Bookings.DepartureDate, DATEDIFF(d,Bookings.ArrivalDate 
    ,Bookings.DepartureDate) AS 'PitchNights' 
FROM 
    Bookings 
WHERE Bookings.ArrivalDate >[email protected] AND Bookings.DepartureDate <[email protected] 

感謝

韋恩

回答

3
SELECT SUM(DATEDIFF(d,Bookings.ArrivalDate,Bookings.DepartureDate)) AS 'PitchNights' 
FROM Bookings 
WHERE Bookings.ArrivalDate >[email protected] AND 
     Bookings.DepartureDate <[email protected] 
+0

感謝JW,快速的問題,如果我想表現出不同的年總額與參數我能不能複製上面的代碼,然後聯盟彼此相鄰他們,例如2011年日期之後的2010年數據? – wafw1971 2013-02-26 10:03:18