sql语句问题 求解

w521111 2011-02-24 04:45:08
表 tab
字段:id,name,num

要求:查出表tab中数据,按num倒序排列,当name重复时只显示num最大的一条
...全文
66 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
w521111 2011-02-24
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 acherat 的回复:]

被你发现了。……
[/Quote]

那个SQL Code框是怎么用的?没找到按钮啊
AcHerat 元老 2011-02-24
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 w521111 的回复:]
select * from tab a where not exists(select 1 from tab b where name=a.name and num>a.num) order by num desc

2楼的自己试试看
3、4楼的应该是num>a.num,不存在比a中num更大的
5楼的括号中少了个where
[/Quote]

被你发现了。
w521111 2011-02-24
  • 打赏
  • 举报
回复
select * from tab a where not exists(select 1 from tab b where name=a.name and num>a.num) order by num desc

2楼的自己试试看
3、4楼的应该是num>a.num,不存在比a中num更大的
5楼的括号中少了个where
快溜 2011-02-24
  • 打赏
  • 举报
回复
 select * from tab a where not exists(select 1 from tab num>a.num and name=a.name)
order by num desc
打一壶酱油 2011-02-24
  • 打赏
  • 举报
回复
select *
from tb t
where not exists (select 1 from tb where id = t.id and num < t.num)
order by num desc
AcHerat 元老 2011-02-24
  • 打赏
  • 举报
回复

select *
from tb t
where not exists (select 1 from tb where name = t.name and num < t.num)
order by num desc

xuam 2011-02-24
  • 打赏
  • 举报
回复
select id,name,max(num) from tab order by num desc
AcHerat 元老 2011-02-24
  • 打赏
  • 举报
回复

select *
from tbt
where not exists (select 1 from tb where name = t.name and num < t.num)
order by num desc

34,590

社区成员

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

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