汇总排序问题(要求系统开支小)

Layto Layto 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我现在SQL语句如下:对某种商品,按商品类型、月份、票号汇总(goodid,convert(char(7),MAKEDATE,120),union_id )
现在我得出的结果没有按MAKEDATE排序,请问结果要按MAKEDATE asc按序显示,(wxlx 为视图)
表数据太多,只求解决办法.
select
grouping(goodid),
grouping(convert(char(7),MAKEDATE,120)),grouping(union_id),

(case when grouping(goodid)=1 then '总计' when grouping(convert(char(7),MAKEDATE,120))=1 then '合计' when grouping(union_id)=1 then '小计' else max(CT_Name) end) as dwmc,
(case when grouping(union_id)=1 then null else max(MAKEDATE) end) as MAKEDATE,
(case when grouping(union_id)=1 then null else max(CT_Code) end) as ct_code,
(case when grouping(union_id)=1 then null else max(GD_Name) end) as GD_Name,
(case when grouping(union_id)=1 then null else max(GD_Spec) end) as GD_Spec,
(case when grouping(union_id)=1 then null else max(BTHNUM) end) as BTHNUM,
(case when grouping(union_id)=1 then sum(QTY_J) else max(QTY_J) end) as QTY_J,
(case when grouping(union_id)=1 then sum(QTY_x) else max(QTY_x) end) as QTY_x,
(case when grouping(union_id)=1 then null else max(GD_Unit) end) as GD_Unit,
(case when grouping(union_id)=1 then null else max(TAXPRICE) end) as TAXPRICE,
(case when grouping(union_id)=1 then null else max(BILLTYPE) end) as BILLTYPE,
(case when grouping(union_id)=1 then null else max(GD_Manufacture) end) as GD_Manufacture,
(case when grouping(union_id)=1 then null else max(CHKNO) end) as CHKNO,
(case when grouping(union_id)=1 then null else max(GD_Code) end) as GD_Code


from wxlx
where goodID in(SELECT lg_goodid FROM Login_GID where lg_cstid='899987 ' and lg_type='00')
and MAKEDATE>='2009-2-1' and MAKEDATE<='2009-3-31 23:59:59'
group by goodid,convert(char(7),MAKEDATE,120),union_id with rollup
...全文

相关推荐

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