douduiti3040 2018-09-07 13:58
浏览 68
已采纳

使用两个参数sql在mysql中添加相同的值

I have a table trade as follows:-

bm  | m   | price | amount | total    | status
USD | BTC | 0.01  | 1      | 0.01     | active
USD | BTC | 0.01  | 2.5    | 0.025    | active
USD | BTC | 0.4   | 0.5    | 0.020    | active 
USD | BTC | 0.4   | 0.22   | 0.088    | active

I want to add amounts of duplicate price i.e 0.01 and 0.4 as well as total together in one output where status is active and show them so that the result is like:-

price | amount  | total
0.01  | 3.5     | 0.035
0.4   | 0.722   | 0.108
  • 写回答

4条回答 默认 最新

  • douying4203 2018-09-07 14:00
    关注

    You could group according to the price and sum the other columns:

    SELECT   price, SUM(amount), SUM(total)
    FROM     trade
    WHERE    status = 'active'
    GROUP BY price
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题