我正在尝试计算2个列值的差的最大值,然后将它们按常见类别(在这种情况下为Symbol)分组。
Symbol mydate mytime myopen High Low myclose
ZEEL 2019-07-29 09:15:00.000 401.1 402.05 400.25 402.05
ZEEL 2019-07-29 09:17:00.000 401.6 402 398.6 400.7
ZEEL 2019-07-29 09:19:47.000 400 400 400 400
YESBANK 2019-07-29 09:15:00.000 95.8 96.05 94.6 95.25
YESBANK 2019-07-29 09:17:00.000 95.2 95.2 94.45 94.45
YESBANK 2019-07-29 09:19:46.000 93.8 93.8 93.8 93.8
WONDI 2019-07-29 09:15:00.000 258.8 258.8 258.75 258.75
(> 12000条以上记录)
我想找到按符号分组的高-低值的最大差异。
所以我尝试了:
select symbol, (high-low) as Diff from dcTbl_29072019
where mytime>='15:01:35.000'
order by symbol
我有:
symbol Diff
AARTIIND 1.34999999999991
AARTIIND 0
ACC 1.25
我现在需要根据符号将上述输出分组
添加带有“按符号分组”的行会返回错误。
要清楚,我想要的输出是:
symbol Diff
AARTIIND 1.34999999999991
ACC 1.25 ... (and So On).
TIA
最佳答案
使用分组子查询的一种方式:
select symbol, (high - low) as diff
from (
select symbol, max(high) as high, min(low) as low
from dcTbl_29072019
where mytime >= '15:01:35.000'
group by symbol
) gr
order by symbol
或者,一口气做到:
select symbol, max(high) - min(low) as diff
from dcTbl_29072019
where mytime >= '15:01:35.000'
group by symbol
order by symbol
关于mysql - 列出SQL中2个列值的最大(差异),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57282436/