27,579
社区成员
发帖
与我相关
我的任务
分享
SELECT [One_project],[Two_project],[Three_project],[XM_ID],[TR_Year],SUM (S_TR) AS S_TRCount,SUM (ZY_TR) AS ZY_TRCount,SUM (HY_TR) AS HY_TRCount,SUM (QT_TR) AS QT_TRCount,SUM(TR_SUM) AS sum_TRCount,GROUPING(XM_ID),GROUPING(TR_Year) FROM [input] join Input_User on input.ID = Input_User.inputID WHERE Input_User.HeadID =" + userID + "and XM_ID IS not NULL GROUP BY One_project,Two_project,Three_project,XM_ID,TR_Year WITH rollup HAVING XM_ID IS NOT NULL
with input_user as
(select 7 as id, 7 inputid,2 as headid,3 as memberid union all
select 8 as id, 7 inputid,2 as headid,6 as memberid union all
select 9 as id, 7 inputid,2 as headid,4 as memberid union all
select 10 as id, 7 inputid,2 as headid,4 as memberid union all
select 11 as id, 7 inputid,2 as headid,4 as memberid ),
input as
(select 7 as id,56 as xm_id,2010 as tr_year ,
400.00 as s_tr, null as zy_tr,null as hy_tr,null as qt_tr ,
400.00 as tr_sum, '子项目'as one_project,'adminaid' as two_project
, 'BB' as three_project
, 1 as tr_moth )
SELECT [One_project],[Two_project],[Three_project],[XM_ID],[TR_Year],
SUM (S_TR) AS S_TRCount,
SUM (convert(int,ZY_TR)) AS ZY_TRCount,
SUM (convert(int,HY_TR)) AS HY_TRCount,
SUM (convert(int,QT_TR)) AS QT_TRCount,
SUM(TR_SUM) AS sum_TRCount,GROUPING(XM_ID),GROUPING(TR_Year)
FROM [input] join Input_User on input.ID = Input_User.inputID
WHERE Input_User.HeadID =2
GROUP BY One_project,Two_project,Three_project,
XM_ID,TR_Year WITH rollup
having xm_id is not null
with input_user as
(select 7 as id, 7 inputid,2 as headid,3 as memberid union all
select 8 as id, 7 inputid,2 as headid,6 as memberid union all
select 9 as id, 7 inputid,2 as headid,4 as memberid union all
select 10 as id, 7 inputid,2 as headid,4 as memberid union all
select 11 as id, 7 inputid,2 as headid,4 as memberid ),
cte1 as
(select inputid,MIN(id) as minid from input_user
group by inputid),、
--CTE1就是对INPUT_USER进行处理的。取出来每个INPUTID对于的最小ID,你后面只要和这个表进行连接就OK 了。