我有以下查询,它似乎对我来说没问题然而当我在SQLPro中运行此查询时,我收到以下错误消息(我认为它可能是特定于sqlite的错误?:
错误:
near "CASE": syntax error (Line 14)
查询
SELECT team, SUM(Win) As Won, SUM(Loss) as Lost, SUM(score) as Score
FROM
( SELECT home_team_id as team,
CASE WHEN home_score > away_score THEN 1 ELSE 0 END as Win,
CASE WHEN home_score < away_score THEN 1 ELSE 0 END as Loss, home_score as score
FROM community_results
UNION ALL
SELECT away_team_id as team
CASE WHEN away_score > home_score THEN 1 ELSE 0 END as Win,
CASE WHEN away_score < home_score THEN 1 ELSE 0 END as Loss, away_score as score
FROM community_results
) t
GROUP BY team
ORDER By Won, Lost DESC, Score
答案 0 :(得分:1)
您之后错过了逗号:
SELECT away_team_id as team
答案 1 :(得分:0)
这个怎么样;)
SELECT team, SUM(Win) As Won, SUM(Loss) as Lost, SUM(score) as Score
FROM
( SELECT home_team_id as team,
CASE WHEN home_score > away_score THEN 1 ELSE 0 END as Win,
CASE WHEN home_score < away_score THEN 1 ELSE 0 END as Loss, home_score as score
FROM community_results
UNION ALL
SELECT away_team_id as team,
CASE WHEN away_score > home_score THEN 1 ELSE 0 END as Win,
CASE WHEN away_score < home_score THEN 1 ELSE 0 END as Loss, away_score as score
FROM community_results
) t
GROUP BY team
ORDER By Won, Lost DESC, Score