关于视图排序

x_bingbing x_bingbing 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
创建了一个视图,按照d排序
结果如下

d m1 m2 m3 .. m12
1
10
11
.
.
2
20
21
22
.
.
3

我想要的是从小到大排序,怎么办
create view testjyl19 as select top 99 DATENAME(dd,createtime) d,max(case when Datepart(month,createtime)=1 then resultdata1 else 0 end) m1,max(case when Datepart(month,createtime)=2 then resultdata1 else 0 end) m2,max(case when Datepart(month,createtime)=3 then resultdata1 else 0 end) m3,max(case when Datepart(month,createtime)=4 then resultdata1 else 0 end) m4,max(case when Datepart(month,createtime)=5 then resultdata1 else 0 end) m5,max(case when Datepart(month,createtime)=6 then resultdata1 else 0 end) m6,max(case when Datepart(month,createtime)=7 then resultdata1 else 0 end) m7,max(case when Datepart(month,createtime)=8 then resultdata1 else 0 end) m8,max(case when Datepart(month,createtime)=9 then resultdata1 else 0 end) m9,max(case when Datepart(month,createtime)=10 then resultdata1 else 0 end) m10,max(case when Datepart(month,createtime)=11 then resultdata1 else 0 end) m11,max(case when Datepart(month,createtime)=12 then resultdata1 else 0 end) m12 from commhistorydata where datepart(year,createtime)=2009 and systemid=1 and deviceid in (select min(deviceid) from devicecongfigtable where regionid=1 and systemid=1 and devicetypeid=18) and datawarningstate<>6 and datawarningstate<>0 and resultdata1<>9999.99 group by datename(day,createtime)

视图语句如上
...全文

相关推荐

评论 16
收藏 已收藏
分享
返回顶部
x_bingbing
MS-SQL Server 34,876 成员 254,635 内容