您好我正在开发一个项目,要求我在Access SQL查询中使用大量列。典型的查询包含几个字段,如下所示:
SELECT ([Score1]+[Score2]+[Score3])*.5 AS [Scores], [Subject] FROM [ScoresTable]
WHERE ([Score1]+[Score2]+[Score3])*.5 > 500
有没有办法将([Score1]+[Score2]+[Score3])*.5
的值赋给变量,所以我实际上可以这样写:
SELECT ([Score1]+[Score2]+[Score3])*.5 AS [Scores] *= VAR*, [Subject]
FROM [ScoresTable] WHERE *VAR* > 500
如果有可能,请告诉我如何取得这样的成绩?
谢谢。
答案 0 :(得分:1)
SELECT sq.Scores, sq.Subject
FROM (
SELECT (Score1+Score2+Score3)*.5 AS Scores, Subject
FROM ScoresTable
) AS sq
WHERE sq.Scores > 500;
如果Score1,Score2或Score3可以为Null,您可能希望使用Nz函数将零替换为Null。