0

另一个简单的问题,我不知道如何解决,想知道您是否可以提供帮助。我需要总计 140 万行数据,每行有一定数量的 PitchNights,第 1 行 = 2,第 2 行 = 26,第 14000 行 = 3 等等,所以如果我只有这 3 行,那么总数将是 31。什么我需要在 2 个设定的日期之间总共有所有的 Pitch 之夜。我尝试了按功能分组,但没有奏效。

SELECT
  Bookings.BookingNumber
  ,Bookings.ArrivalDate
  ,Bookings.DepartureDate, DATEDIFF(d,Bookings.ArrivalDate
  ,Bookings.DepartureDate) AS 'PitchNights'
FROM
  Bookings
WHERE Bookings.ArrivalDate >=@ArrivalDate AND Bookings.DepartureDate <=@DepartureDate

谢谢

韦恩

4

1 回答 1

3
SELECT  SUM(DATEDIFF(d,Bookings.ArrivalDate,Bookings.DepartureDate)) AS 'PitchNights'
FROM    Bookings
WHERE   Bookings.ArrivalDate >=@ArrivalDate AND 
        Bookings.DepartureDate <=@DepartureDate
于 2013-02-26T09:54:20.107 回答