SELECT sum(case when b.Docu_Status='2' then 1 else 0 end) AS 扫描,
sum(case when b.Docu_Status='5' then 1 else 0 end) AS 质检,
sum(case when b.Docu_Status='11' then 1 else 0 end) AS 总质检,
sum(case when b.Docu_Status='14' then 1 else 0 end) AS 完成
 
FROM UDP_Project as a INNER JOIN UDP_Document as b ON a.Project_Id = b.Docu_ForPro
如上SQL语句,我希望查询出来的结果再增加一列‘总计’,就是把这几个sum的和加起来
类似于这样
SELECT sum(case when b.Docu_Status='2' then 1 else 0 end) AS 扫描,
sum(case when b.Docu_Status='5' then 1 else 0 end) AS 质检,
sum(case when b.Docu_Status='11' then 1 else 0 end) AS 总质检,
sum(case when b.Docu_Status='14' then 1 else 0 end) AS 完成,
sum(...) as 总计
FROM UDP_Project as a INNER JOIN UDP_Document as b ON a.Project_Id = b.Docu_ForPro
有没有办法实现~

解决方案 »

  1.   

    SELECT sum(case when b.Docu_Status='2' then 1 else 0 end) AS 扫描,
    sum(case when b.Docu_Status='5' then 1 else 0 end) AS 质检,
    sum(case when b.Docu_Status='11' then 1 else 0 end) AS 总质检,
    sum(case when b.Docu_Status='14' then 1 else 0 end) AS 完成,
    count(1) as 总计
    FROM UDP_Project as a INNER JOIN UDP_Document as b ON a.Project_Id = b.Docu_ForPro
      

  2.   

    SELECT sum(case when b.Docu_Status='2' then 1 else 0 end) AS 扫描,
    sum(case when b.Docu_Status='5' then 1 else 0 end) AS 质检,
    sum(case when b.Docu_Status='11' then 1 else 0 end) AS 总质检,
    sum(case when b.Docu_Status='14' then 1 else 0 end) AS 完成,
    count(1) as 总计
    FROM UDP_Project as a INNER JOIN UDP_Document as b ON a.Project_Id = b.Docu_ForPro+++
      

  3.   


    SELECT sum(case when b.Docu_Status='2' then 1 else 0 end) AS 扫描,
    sum(case when b.Docu_Status='5' then 1 else 0 end) AS 质检,
    sum(case when b.Docu_Status='11' then 1 else 0 end) AS 总质检,
    sum(case when b.Docu_Status='14' then 1 else 0 end) AS 完成,
    SUM(case b.Docu_Status when '2' then 1
     when '5' then 1
     when '11' then 1
     when '14' then 1
     ELSE 0 END) as 总计
    FROM UDP_Project as a INNER JOIN UDP_Document as b ON a.Project_Id = b.Docu_ForPro
      

  4.   


    加个
    WHERE b.Docu_Status in(2,5,11,14) 不就OK了
    SELECT sum(case when b.Docu_Status='2' then 1 else 0 end) AS 扫描,
    sum(case when b.Docu_Status='5' then 1 else 0 end) AS 质检,
    sum(case when b.Docu_Status='11' then 1 else 0 end) AS 总质检,
    sum(case when b.Docu_Status='14' then 1 else 0 end) AS 完成,
    count(1) as 总计
    FROM UDP_Project as a INNER JOIN UDP_Document as b ON a.Project_Id = b.Docu_ForPro
    WHERE b.Docu_Status in(2,5,11,14)