请教大虾们一个简单的查询问题,望赐教!谢谢...

czciou 2010-08-23 05:20:48
表:mytable
Myid price
1 8
2 4
2 6
3 3
3 5
3 7
4 10
4 11
4 50
4 90

查询后:
Myid price
1 8
2 6
3 7
4 90

查询语句怎么写啊?先谢谢了~



...全文
73 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
czciou 2010-08-23
  • 打赏
  • 举报
回复
太感谢 了~这么快就得到你们的帮助~
Mark杨 2010-08-23
  • 打赏
  • 举报
回复

select myid,price = max(price) from @tb group by myid
xmx2009 2010-08-23
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 albert_sky 的回复:]
SQL code
select myId,max(price) from mytable
group by myId
order by myId
[/Quote]
UP
Mark杨 2010-08-23
  • 打赏
  • 举报
回复


-->测试数据
declare @tb table (Myid int,price int)

insert into @tb
select 1,8 union all
select 2,4 union all
select 2,6 union all
select 3,3 union all
select 3,5 union all
select 3,7 union all
select 4,10 union all
select 4,11 union all
select 4,50 union all
select 4,90

select myid,max(price) from @tb group by myid

--结果
myid
----------- -----------
1 8
2 6
3 7
4 90
hao1hao2hao3 2010-08-23
  • 打赏
  • 举报
回复

select myid,max(price) from mytable
group by myid


百年树人 2010-08-23
  • 打赏
  • 举报
回复
select myid,max(price) as price from tb group by myid
Mark杨 2010-08-23
  • 打赏
  • 举报
回复
select Myid,max(price) from mytable group by Myid
albert_sky 2010-08-23
  • 打赏
  • 举报
回复
select myId,max(price) from mytable
group by myId
order by myId

22,209

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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