如何写这条sql语句啊?????

农夫it 2011-09-22 05:22:40
是这样的 表中有三列

id price nation
1 100 中国
2 80 中国
3 800 美国
4 900 美国
5 100 日本

我要查询nation不重复,且price是最低的,结果是
id price nation
2 80 中国
3 800 美国
5 100 日本


高手赐教啊.....
...全文
59 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
农夫it 2011-09-22
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 ssp2009 的回复:]

SQL code
select * from tb a
where id=(select top 1 id from tb where nation=a.nation order by price)
[/Quote]

这个可以啊,... 你们速度真快
chuanzhang5687 2011-09-22
  • 打赏
  • 举报
回复
select * from tb a
where price=(select min(price) from tb where nation=a.nation)
--修改一下,price最小
chuanzhang5687 2011-09-22
  • 打赏
  • 举报
回复
select * from tb a
where price=(select max(price) from tb where nation=a.nation)
NBDBA 2011-09-22
  • 打赏
  • 举报
回复
select * from tb a
where NOT EXISTS (
SELECT 1
FROM TB
WHERE nation=a.nation
AND price < A.price
OR price = A.price
AND ID < A.ID
)
快溜 2011-09-22
  • 打赏
  • 举报
回复
select * from tb a
where id=(select top 1 id from tb where nation=a.nation order by price)

22,294

社区成员

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

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