想取相同名称的记录中最近的一条

DavidSun2014 2012-12-23 01:50:52
如下所示的数据:
id name change_date order_no
1 电话 2012-12-10 0001
2 电脑 2012-12-10 0002
3 电灯 2012-12-10 0003
4 电话 2012-12-20 0004
5 电脑 2012-12-20 0005
6 电灯 2012-12-20 0006
==========================================
现在想要通过日期change_date字段找出2012-12-21前的最近一条电脑的记录。
请问SELECT查询语句怎么写?
select * from table where change_date<='2012-12-21' and name='电脑'
用这SQL语句查询出来有两条记录,我只想要order_no为005的这条记录。不知这个SQL语句怎么写?请高手帮忙!
...全文
113 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
ACMAIN_CHM 2012-12-23
  • 打赏
  • 举报
回复
参考下贴中的多种方法 http://blog.csdn.net/acmain_chm/article/details/4126306 [征集]分组取最大N条记录方法征集,及散分....
Rotel-刘志东 2012-12-23
  • 打赏
  • 举报
回复
select * from table where change_date<='2012-12-21' and name='电脑'order by order_no limit;
WWWWA 2012-12-23
  • 打赏
  • 举报
回复
Select * from table where change_date<='2012-12-21' and name='电脑' ORDER BY order_no DESC LIMIT 1

56,679

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧