除了分组以外还有什么方法过滤重复的字段

hdj_05 2004-08-12 08:37:00
我用视图把两个表用分组但是会出现重复的字段,一个表(user)中用户名,id都只有唯一纪录,还有一个表(content)中一个用户,内容允许有多条纪录,我想找出不同用户名的最后10个内容。
...全文
194 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq3080 2004-08-12
  • 打赏
  • 举报
回复
declare @AA int,@BB int
select @AA = usercode from user order by usercode
select @bb = usercode from user order by usercode desc
while @bb <@AA
begin
select top 10 * from content where usercode = @bb group by usercode,title,content.id order by usercode, content.id desc
set @bb = @bb+1
end
qq3080 2004-08-12
  • 打赏
  • 举报
回复
不知是否是這樣兩個表:User(userid,usercode),Content(usercode,title,id)
如果是:
select a.userid, top 10 b.usercode,b.title,b.id
from user a left join content b on a.usercode = b.usercode
order by b.id desc
hdj_05 2004-08-12
  • 打赏
  • 举报
回复
有两个表(user,content),user表中的userid,usercode(自加)是唯一的,在content表中的usercode是对应user表中的usercode可以多个出现,title是text型的,id是自加的,现在要选择出来不同usercode的最后10组内容。
zjcxc 元老 2004-08-12
  • 打赏
  • 举报
回复
不明,举例说明.
zonelive 2004-08-12
  • 打赏
  • 举报
回复
用distinct塞选,中间用临时表交换也可以做到

34,593

社区成员

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

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