汇总排序问题(要求系统开支小)
我现在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
现在我得出的结果没有按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
...全文
相关推荐
Excel预算专项模板-年终公司各部门开支预算表
Excel预算专项模板-年终公司各部门开支预算表
DataTable分类求和,分类汇总,排序
对于这个问题,自己郁闷了四五天的时间,之后终于做出来了,分享一下. 主要是从操作内存中的datatable表,而非直接操作数据库,筛选,去除重复行,sum求和,根据某个字段进行排序等等操作....
日常开支记录系统
简单VB与数据库之间的通信.以及DATAGRID的使用.功能有 浏览,统计和每天的添加..仅供新手学习代码只用。
纯js对象数组排序汇总处理类
本资源包含一个js文件和一个作为demo的html文件。用浏览器打开html文件,f12打开开发者工具查看运行结果。js中包含一个类,该类的主要功能是:对对象数组进行多字段排序和汇总。调用方法类似: 1、排序 :new SPArraySortHelper(数据, 分组排序字段, 汇总字段).sort() 2、汇总:new SPArraySortHelper(数据, 分组排序字段, 汇总字段).gather()
GrivdView操作汇总,分页,排序,分组,汇总等
GrivdView操作汇总,分页,排序,分组,汇总等


