菜鸟问个查询结果排序的问题!请大家帮忙!

hzgniit 2008-02-27 03:11:28
假设一个表有A,B两字段 A字段的内容表示年份 B字段的内容表示月份
查询出A和B 查询的结果怎么按年月排序?
请大家教教我!
...全文
163 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
areswang 2008-02-27
  • 打赏
  • 举报
回复
order by A desc,B desc
gahade 2008-02-27
  • 打赏
  • 举报
回复
在后面加desc即可
areswang 2008-02-27
  • 打赏
  • 举报
回复
------------加个DESC
if object_id('tb') is not null
drop table tb
go
create table tb(A int, B int)
insert into tb
select 2007,1 union all
select 2007,10 union all
select 2007,2 union all
select 2007,4 union all
select 2007,3 union all
select 2007,5 union all
select 2008,2 union all
select 2007,1
select A,B from tb
order by A,B DESC
hzgniit 2008-02-27
  • 打赏
  • 举报
回复
忘说了,是按年月降序排列
请大家重新修改一下!
谢谢大家!
gahade 2008-02-27
  • 打赏
  • 举报
回复
字符型月份的话
select * from 表
order by a+right('0'+b,2)
JL99000 2008-02-27
  • 打赏
  • 举报
回复
if object_id('tb') is not null
drop table tb
go
create table tb(A int, B int)
insert into tb
select 2007,1 union all
select 2007,10 union all
select 2007,2 union all
select 2007,4 union all
select 2007,3 union all
select 2007,5 union all
select 2008,2 union all
select 2007,1
select A,B from tb
order by A,B
gahade 2008-02-27
  • 打赏
  • 举报
回复
select * from 表
order by a,b

34,874

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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