查询问题

gohands 2004-09-09 04:27:43
有一个表table有三各字段
a b c
a1 23 1
a1 22 2
a2 2 3
a2 3 2

现在我想得到
a1 22 2
a2 3 3
如何做
就是每个a选择当c最大时查询的结果 3Q
...全文
94 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
zheninchangjiang 2004-09-09
  • 打赏
  • 举报
回复
3K党?
gaodongsheng 2004-09-09
  • 打赏
  • 举报
回复
不好意思写错了
gohands 2004-09-09
  • 打赏
  • 举报
回复
3K :zicxc(冒牌邹建 V0.3)
gaodongsheng 2004-09-09
  • 打赏
  • 举报
回复
select * from tablename
group by a having c=max(c)
bernice99 2004-09-09
  • 打赏
  • 举报
回复
select a.*
from table a,(select a,max(c) from table group by a) b
where a.a=b.a and a.c=b.c

这里已经有多次提出类似的问题了。
gohands 2004-09-09
  • 打赏
  • 举报
回复
TO:lsxaa(小李铅笔刀)
没有为第 2 列(属于 'bb')指定列。

3Q
zicxc 2004-09-09
  • 打赏
  • 举报
回复
select * from tablename a
where c=(select max(c) from tablename where a=a.a)
lsxaa 2004-09-09
  • 打赏
  • 举报
回复
select aa.*
from table aa,(select a,max(c) from table group by a) bb
where aa.a=bb.a and aa.c=bb.c
zicxc 2004-09-09
  • 打赏
  • 举报
回复
select * from tablename a
where c=(select max(c) from tablename where a=a.a)

34,590

社区成员

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

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