sql暴露产品的日期

时间:2014-06-19 10:58:05

标签: sql distinct validates-uniqueness-of

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

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

1 个答案:

答案 0 :(得分:0)

    SELECT productID,DATEDIFF(MAX(endDate),MIN(startDate))+1 DAYS FROM
   db.new_table GROUP BY productID