T-sql get min and max value for each day

前端 未结 1 841
眼角桃花
眼角桃花 2021-01-14 04:10

I am trying to write a query where for each day I get the minimum and maximum price for each item from price details table.

In price details table prices are set mul

相关标签:
1条回答
  • A simple group by should work:

    select  cast(price_set_date as date) as [Date]
    ,       exch_ticker 
    ,       min(buy_price) as MinPrice
    ,       max(buy_price) as MaxPrice
    from    price_details as p
    group by 
            exch_ticker
    ,       cast(price_set_date as date)
    

    Not sure why your example query is using a self join. If there's a good reason please add an explanation to your question.

    0 讨论(0)
提交回复
热议问题