这样的查询怎么写?上次别人回的结了贴才发现不行的。没分了,请原谅

stevegates 2003-08-25 12:36:54
有一个表有若干字段,其中一个字段topic有ST,SL,CM三个值,另一个date字段。
我希望得到每个topic相同的纪录中date最大的前三条(一共九条),怎么写?

谢谢。
...全文
60 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
stevegates 2003-08-29
  • 打赏
  • 举报
回复
感谢大家.
Ianlan 2003-08-26
  • 打赏
  • 举报
回复
用union all可以实现的
yujohny 2003-08-26
  • 打赏
  • 举报
回复
//感谢,能不能告诉我 tem是什么?

tem是给你“表”定义的别名
CrazyFor 2003-08-25
  • 打赏
  • 举报
回复
select * from 表 a where (select count(*) from 表 b where a.topic=b.topic and b.date字段>=a.date字段)<=3
lynx1111 2003-08-25
  • 打赏
  • 举报
回复
1.
select * from topic tem where time in (select top 3 time from topic where topic=tem.topic order by time desc)order by topic

2.
select * from topic a where (select count(*) from topic b where a.topic=b.topic and b.TIME<=a.TIME)<=3 ORDER BY topic
stevegates 2003-08-25
  • 打赏
  • 举报
回复
感谢,能不能告诉我 tem是什么?
pengdali 2003-08-25
  • 打赏
  • 举报
回复
select * from 表 tem where date in (select top 3 date from 表 where topid=tem.topid order by date desc)

22,207

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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