0

我正在尝试在Ready我的查询中添加一个名为的列,该列检查总和Complete是否 = 总和,Total如果为真,则放置“Y”,如果为假,则放置“N”。

这是我的查询,可以生成 4 列

 SELECT pc.Sub,
    SUM(CASE WHEN `SheetStatus` LIKE 'Complete' THEN 1 ELSE 0 END) AS 'Complete',
    SUM(CASE WHEN `SheetStatus` LIKE 'Not started' THEN 1 ELSE 0 END) AS 'Not Started',
    SUM(CASE WHEN `CheckSheet` LIKE '%' THEN 1 ELSE 0 END) AS 'Total'        
FROM `pc`
Group By pc.Sub WITH ROLLUP

如果可能的话,我只是不知道如何创建额外的列。问候

4

2 回答 2

1

尝试外部 SELECT

SELECT `Complete`, 
       `Not Started`, 
       `Total`, 
       CASE WHEN `Complete` = `Total` THEN 'Y' ELSE 'N' END `Ready`
  FROM (
SELECT pc.Sub,
    SUM(CASE WHEN `SheetStatus` LIKE 'Complete' THEN 1 ELSE 0 END) AS `Complete`,
    SUM(CASE WHEN `SheetStatus` LIKE 'Not started' THEN 1 ELSE 0 END) AS `Not Started`,
    SUM(CASE WHEN `CheckSheet` LIKE '%' THEN 1 ELSE 0 END) AS `Total`        
FROM `pc`
GROUP BY pc.Sub WITH ROLLUP) t
于 2013-05-09T03:47:05.203 回答
0

尝试这个:

SELECT pc.Sub,
    SUM(IF(`SheetStatus`='Complete',1,0) AS 'Complete',
    SUM(IF(`SheetStatus`='Not started',1,0) AS 'Not Started',
    SUM(IF(`CheckSheet` LIKE '%',1,0) AS 'Total'
    IF(SUM(IF(`CheckSheet` LIKE '%',1,0) = SUM(IF(`SheetStatus`='Complete',1,0),"Y","N") AS Ready
FROM `pc`
Group By pc.Sub WITH ROLLUP
于 2013-05-09T03:48:53.663 回答