TSQL - 如何比较卷数

问题描述 投票:0回答:3

我的报告的日期范围是每天的总体积计数。我不知道如何编写TSQL来比较给定日期范围内的低容量。例如,如何确定给定日期的低容量计数是581?

enter image description here

sql-server tsql
3个回答
0
投票
SELECT MIN(volume_count) as Min_volume_count FROM tableName WHERE date= 'yourdate'

SELECT MIN(volume_count) as Min_volume_count FROM tableName WHERE date= '2018-03-01'

0
投票

另一种选择是使用窗口函数min()

Select *
      ,MinVol    = min(Volume) over () 
      ,Change    = Volume - min(Volume) over () 
 from YourTable

返回

Date        Volume  MinVol  Change
2018-03-01  581     581     0
2018-02-22  9480    581     8899
2018-02-15  10082   581     9501
2018-02-08  10082   581     9501
2018-02-01  10504   581     9923

0
投票
select ddate, min(volume) as mmin 
from table 
group by ddate 
order by ddate 
© www.soinside.com 2019 - 2024. All rights reserved.