【问题标题】:Sum of Quantity for the Max price in same time同一时间最高价格的数量总和
【发布时间】:2018-04-19 03:29:34
【问题描述】:

表格数据:

Time    BUY  SELL   BUY_Qty SELL_Qty
3:00    20     10      5     2
3:00    20     10      5     1
3:00    20     10      5     4
3:00    10     20      2     3
3:00    10     20      2     3

以上数据的预期结果:

Time    max(BUY)  MIN(SELL)   BUY_Qty SELL_Qty
3:00       20          10       15      7

【问题讨论】:

  • 要按时间分组吗?
  • 是的。我想按时间分组
  • 我想要最高买入价的买入数量和最低卖出价的卖出数量的总和
  • 这是 SQL 还是。 ..?
  • 在 ORACLE 中,我需要一个 oracle 查询

标签: sql oracle sum max aggregate-functions


【解决方案1】:

这是您可以在 oracle 中使用的查询:

select t1.Time, max_buy, min_sell, SUM(t1.BUY_Qty), SUM(t1.SELL_Qty) 
from table1 t1
join(SELECT Time, MAX(BUY) as max_buy, MIN(SELL) as min_sell
    FROM Table1 GROUP BY Time) t2 
    on t1.time=t2.time and t1.buy=t2.max_buy
group by t1.Time, max_buy, min_sell

SQL DEMO HERE

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-07
    • 2015-08-13
    • 2013-02-22
    相关资源
    最近更新 更多