0

我尝试使用计数案例来计算某个列(runs.Finish)中的记录(如果它们等于一个)。

当我像下面第三行那样添加计数案例时,我似乎无法让它工作。

SELECT
  `jockeys`.`JockeyInitials`,
  `jockeys`.`JockeySurName` ,
  COUNT(  `runs`.`JockeysID` ), 
  COUNT( CASE WHEN `runs`.`Finish`=1 THEN 1 ELSE NULL END ) AS `runs`.`Finish` , 
  SUM(  `runs`.`StakeWon` ) 
FROM runs, jockeys
WHERE  `runs`.`JockeysID` =  `jockeys`.`JockeysID` 
  AND  `runs`.`JockeysID` >=1
  AND  `runs`.`JockeysID` <=100
GROUP BY  `runs`.`JockeysID`
4

1 回答 1

0

您的查询应该是(按列检查分组和案例语句列的别名)

SELECT
  `jockeys`.`JockeyInitials`,
  `jockeys`.`JockeySurName` ,
  COUNT(  `runs`.`JockeysID` ), 
  COUNT( CASE WHEN `runs`.`Finish`=1 THEN 1 ELSE NULL END ) AS `Finish` , 
  SUM(  `runs`.`StakeWon` ) 
FROM runs, jockeys
WHERE  `runs`.`JockeysID` =  `jockeys`.`JockeysID` 
  AND  `runs`.`JockeysID` >=1
  AND  `runs`.`JockeysID` <=100
GROUP BY  `jockeys`.`JockeyInitials`,
  `jockeys`.`JockeySurName`
于 2012-09-26T20:16:16.983 回答