求sql语句!!!!

麻子Mozart 2009-02-13 05:06:44
现有A表如下:主键(A1,A3)
A1(int) A2(int) A3(int) A4(int)
10 3 3 6
10 5 6 3
10 8 9 1
12 2 2 5
12 6 3 6
15 1 2 7
想得到同一A1的最大A2的所有记录
结果:
10 8 9 1
12 6 3 6
15 1 2 7

...全文
109 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
我也发过类似的帖子,看结果:
http://topic.csdn.net/u/20090102/22/b7694b23-d874-4525-b462-70f978959f22.html

sql很经典的问题。。
橙子撸代码 2009-02-14
  • 打赏
  • 举报
回复
支持1楼
必须用select嵌套
PandaIT 2009-02-14
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 ojlovecd 的回复:]
SQL code
select * from A a1 where A2=(select max(A2) from A a2 where a1.A1=a2.A1)
[/Quote]

此SQL语句刚刚滴
PandaIT 2009-02-14
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 ojlovecd 的回复:]
SQL code
select * from A a1 where A2=(select max(A2) from A a2 where a1.A1=a2.A1)
[/Quote]

此SQL语句刚刚滴
bhtfg538 2009-02-14
  • 打赏
  • 举报
回复
sql 2005

用 这个最快
或者
使用 Row_number()
select a1,a2,a3,a4
from
(
select RANK() over(PARTITION BY a1 Order by a2 desc) Sortno,a1,a2,a3,a4
from A
)
where Sortno =1
xuqunying0545 2009-02-14
  • 打赏
  • 举报
回复
up
冰岛男孩 2009-02-14
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 chinesesdn 的回复:]
关注
[/Quote]
支持一楼的
chinesesdn 2009-02-13
  • 打赏
  • 举报
回复
关注
czbbbs 2009-02-13
  • 打赏
  • 举报
回复
select a1,a2,a3,a4
from
(
select RANK() over(PARTITION BY a1 Order by a2 desc) Sortno,a1,a2,a3,a4
from A
)
where Sortno =1
  • 打赏
  • 举报
回复
select * from A where A2=(select max(A2) from A a2 where a1.A1=a2.A1)
lyymax 2009-02-13
  • 打赏
  • 举报
回复

select table1.* from table1, (select A1, Max(A2) A2 from table1 group by A1) table2
where table1.a1 = table2.a1 and table1.a2=table2.a2
我姓区不姓区 2009-02-13
  • 打赏
  • 举报
回复

select * from A a1 where A2=(select max(A2) from A a2 where a1.A1=a2.A1)

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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