select语句怎样对某个表的某个字段的值由大到小排列?

thomsonyin 2003-10-20 11:22:54
有一个表a
select code,name,sum(count) as total group by code,name
问题是我要对汇总的total按由大到小排列:
用order by total 吗?
...全文
55 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
大地精灵 2003-10-21
  • 打赏
  • 举报
回复
order by 列名 DESC //降序
order by 列名 ASC //升序
wujunwei 2003-10-21
  • 打赏
  • 举报
回复
同上order by 列名 desc/asc
kingting 2003-10-21
  • 打赏
  • 举报
回复
你的问题应该是分组排序的意思
例:
code name count
==============
1 a 23
1 a 10
2 b 4
2 b 7
………………

统计要求应该是:
(1-a):23+10=33
(2-b):4+7=11

下面语句可以实现
select code, sum(count) as totalfrom tb1
where …
group by code
order by total
NotReady 2003-10-21
  • 打赏
  • 举报
回复
select distinct a.dj,a.jxjyjb from examinee,(select distinct sum(count) as dj,jxjyjb from examinee group by jxjyjb) as a where a.jxjyjb=examinee.jxjyjb order by dj desc
yurenjf 2003-10-21
  • 打赏
  • 举报
回复
同意楼上
gmxlj 2003-10-21
  • 打赏
  • 举报
回复
select code,name,sum(count) as total order by total (DESC或ASC) group by code,name
甜而不腻 2003-10-21
  • 打赏
  • 举报
回复
order by total DESC //降序
order by total ASC //升序
fhuibo 2003-10-21
  • 打赏
  • 举报
回复
order by 列名 DESC //降序
order by 列名 ASC //升序
herofy 2003-10-21
  • 打赏
  • 举报
回复
用Having
chenkandy 2003-10-21
  • 打赏
  • 举报
回复
select code,name,sum(count) as total
from a
group by code,name
order by total desc
這樣一定可以的,sql問題,本人願意和大家共免
txmjs 2003-10-21
  • 打赏
  • 举报
回复
up
gx 2003-10-20
  • 打赏
  • 举报
回复
试一试
select code,name,sum(count) as total from table group by code,name order by sum(count) desc
sql server2000 下通过。
jijun 2003-10-20
  • 打赏
  • 举报
回复
order by total DESC //降序
order by total ASC //升序

5,387

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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