dongye6377 2015-08-19 12:18
浏览 80
已采纳

如何在mysql查询中添加多个限制?

I want to select SUM of last 200,100 and 50 rows of close price from a table in a single query. given below is the query for 200 rows.

SELECT SUM(Close_price) as tot200 FROM cash_data ORDER BY date_added LIMIT 0,200 

can anyone help me with this.

  • 写回答

3条回答 默认 最新

  • doutuoji8418 2015-08-19 12:28
    关注

    You can use sub queries -

    SELECT 
    (SELECT SUM(Close_price) FROM cash_data ORDER BY date_added LIMIT 0,200) as tot200, 
    (SELECT SUM(Close_price) FROM cash_data ORDER BY date_added LIMIT 0,100)  as tot100,
    (SELECT SUM(Close_price) FROM cash_data ORDER BY date_added LIMIT 0,50)  as tot50
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改