关于group by的问题,谢谢!

DCD 2006-07-20 12:14:24
a b c
1 2 2
2 2 3
2 3 4

我要得到,b相同的只留一个,按c排序

也就是这样:
a b c
1 2 2
2 3 4

b相同的好弄,可加上排序就不行了
select b from xxx group by b
如果加上order by c asc 就报错“不包含作为合计函数一部分的特定表达式”
应该是,最后得到2条数据,而不是3条,请高人指教!
...全文
116 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
littlelam 2006-07-20
  • 打赏
  • 举报
回复
pzhuyy(喝小酒泡尼姑) ( ) 信誉:100
正解
littlelam 2006-07-20
  • 打赏
  • 举报
回复
晕,写错了...
littlelam 2006-07-20
  • 打赏
  • 举报
回复
select * from xxx where b in(select b from xxx group by b) order by c asc
pzhuyy 2006-07-20
  • 打赏
  • 举报
回复
select b,min(c) from #temp group by b order by min(c) desc
杨风79 2006-07-20
  • 打赏
  • 举报
回复
写错了,应该是:a改成b
select * from tablename t where id in(select top 1 id from tablename where b=t.b order by c ) 'id为自动编号

杨风79 2006-07-20
  • 打赏
  • 举报
回复
select * from tablename t where id in(select top 1 id from tablename where a=t.a order by c ) 'id为自动编号

28,408

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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