T-SQL Multiple grouping

后端 未结 5 914
野性不改
野性不改 2021-01-13 13:46

I have follwing data :

Product Price   StartDate                   EndDate
Apples  4.9     2010-03-01 00:00:00.000     2010-03-01 00:00:00.000
Apples  4.9           


        
5条回答
  •  不要未来只要你来
    2021-01-13 14:32

    Here is a SQLFiddle demo

    with t2 as 
    (
    select t1.*,
    (select count(Price) 
      from t 
      where startdatet1.price
            and Product=t1.Product
    )
    rng  
    from t as t1
    )
    select Product,Price,min(startDate),max(EndDate)  
    from t2 group by Product,Price,RNG
    order by 3
    

提交回复
热议问题