急求一条查询语句

joelbh 2005-10-14 10:01:41
在一个文章表里,有7种类别的文章记录,现在想从每种类别抽取最新的一条记录,总共抽取7条记录,这条查询语句该怎么写?
...全文
181 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
wangdehao 2005-10-14
  • 打赏
  • 举报
回复
select * from Tablename where id in(select MAX(id) from Tablename group by 类别)
zlp321002 2005-10-14
  • 打赏
  • 举报
回复
--取最新记录方法,参考:
http://blog.csdn.net/zlp321002/archive/2005/03/02/307667.aspx

ztfuqing 2005-10-14
  • 打赏
  • 举报
回复
select top 1 from biao where class_id in(select class_id from biao)
wukele 2005-10-14
  • 打赏
  • 举报
回复
select * from wenzhangtable exists(select id,max(shijian) from wenzhangtable groupby类别 )
rivery 2005-10-14
  • 打赏
  • 举报
回复
类别固定的话,建立个视图。
select top 1 * from tablename where type='1' order by colname
union
select top 1 * from tablename where type='2' order by colname
...
bugchen888 2005-10-14
  • 打赏
  • 举报
回复
select * from tablename a where not exists (select 1 from tablename b
where a.类别=b.类别
and a.id<b.id)

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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