求一条查询语句

gxszkj 2006-05-15 09:18:12
各位大侠,请看一下我数据库中字段:
id    名称   编号   日期
1 11 A 2006-1-1
2 22 B 2006-1-3
3 33 B 2006-3-2
4 44 A 2006-1-2
5 55 B 2006-2-3
6 66 C 2006-3-1


现在我想实现的效果是:按照时间的先后顺序,选出表中编号不同的数据各一条,比如:编号为:A的数据选一条,B的选一条,C的选一条,选时间最新的
...全文
134 9 打赏 收藏 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
starsword 2006-05-15
  • 打赏
  • 举报
回复
select * from table a where id in(select top 1 id from table where 编号=a.编号 order by 日期 desc)

谁来帮我解释下这句SQL啊,运行结果正确,可我看不太懂,不太理解?
icefire988 2006-05-15
  • 打赏
  • 举报
回复
那么快结帖了
select * from test t where exists (select id from test where 编号 = t.编号 and 日期 < t.日期 )
shweze 2006-05-15
  • 打赏
  • 举报
回复
select * from table where id in(select max(id) from table group by 编号)
银狐被占用 2006-05-15
  • 打赏
  • 举报
回复
select * from table where 日期 in(select max(日期) from table group by 编号)
x03570227 2006-05-15
  • 打赏
  • 举报
回复
select distinct * from table order by 日期
试试
hj3793 2006-05-15
  • 打赏
  • 举报
回复
select * from table a where id in(select top 1 id from table where 编号=a.编号 order by 日期 desc)
gxszkj 2006-05-15
  • 打赏
  • 举报
回复
错了~~~
zhenmeiyisi 2006-05-15
  • 打赏
  • 举报
回复

没测试,试试吧
select * from table where 编号 in(select 编号,max(日期) from table group by 编号)

28,402

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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