du5910 2016-07-21 08:25
浏览 165

如何找到我的查询的第二个最大值

Here is my SQL query to find a row in currency_price table grouped by maximum date of inserting to table. My question is how to find the second maximum. I mean how can I change this query to find the second maximum row in each group:

select currency_id,buy,sell 
from (select * from currency_price  order by `currency_id`, cu_date desc,buy,sell) x 
group by `currency_id`

with this query i found a row for each id so for example i have sell and buy for each id .exm:

id    sell buy
1000  500  480
1001  20   19
...

but here i want the second maximum date for each id.

I know some query to find second maximum but all does not take me to my answer.

  • 写回答

3条回答 默认 最新

  • doupeng6890 2016-07-21 08:29
    关注

    If it is MySql then Use LIMIT 1,1; # Retrieve rows [start with rec]1-[fetch rec count]1

    http://dev.mysql.com/doc/refman/5.7/en/select.html

    评论

报告相同问题?

悬赏问题

  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥20 java在应用程序里获取不到扬声器设备