0

我有一张包含以下数据的表格

ProductID          StartDate     EndDate
TT1                1 May 2013    10 May 2013
TT1                8 May 2013    14 May 2013
TT2                6 May 2013    12 May 2013
TT2                8 May 2013    12 May 2013

结果需要显示以下计数

TT1               14  (Note this is the 10 days from the 1 record and the 11,12,13,14 May)
TT2               7   (Note this for the 6-12 rec
4

1 回答 1

0
    SELECT productID,DATEDIFF(MAX(endDate),MIN(startDate))+1 DAYS FROM
   db.new_table GROUP BY productID
于 2014-06-20T03:09:41.340 回答