Access 2007 中的子查询问题
Subquery Issue in Access 2007
我有一个使用 Access 2007 的项目,但正在努力编写一个简单的子查询。在记录了特定比率后,我正在尝试从接下来的 6 次 table 中获取结果。
我希望以下代码可以在 Access 中运行:
SELECT [runner name], [race ID], [race date], [placing], [class]
FROM runners
WHERE [runner name] IN
(SELECT [runner name] from 6F Full Form WHERE [ratio] >9
ORDER BY [runner name], [race ID], [date], [placing], [class];
我收到以下错误消息。注意 6F Full Form
是我编写的查询,我正尝试在子查询中使用它。
Syntax error in query expression '[runner name] IN (SELECT [runner name] from 6F Full Form WHERE [ratio] >9
试试这个:
(SELECT [runner name]
FROM [6F Full Form]
WHERE [ratio] >9
ORDER BY [runner name], [race ID], [date], [placing], [class]);
您当前 SQL 代码的问题是 field/table/query 包含空格的名称或 reserved words 必须用方括号括起来 - 因此
from 6F Full Form WHERE
应该写成:
from [6F Full Form] WHERE
您的 order by
条款中也可能存在错字:
SELECT ..., [race date], ...
...
ORDER BY ..., [date], ...;
^--------------- Should this be [race date]?
值得补充的是,您也可以使用联接来实现此目的,例如:
select
r.[runner name],
r.[race id],
r.[race date],
r.[placing],
r.[class]
from
runners r inner join
(select distinct f.[runner name] from [6f full form] f where f.[ratio] > 9) q
on r.[runner name] = q.[runner name]
order by
r.[runner name],
r.[race id],
r.[race date],
r.[placing],
r.[class]
我有一个使用 Access 2007 的项目,但正在努力编写一个简单的子查询。在记录了特定比率后,我正在尝试从接下来的 6 次 table 中获取结果。
我希望以下代码可以在 Access 中运行:
SELECT [runner name], [race ID], [race date], [placing], [class]
FROM runners
WHERE [runner name] IN
(SELECT [runner name] from 6F Full Form WHERE [ratio] >9
ORDER BY [runner name], [race ID], [date], [placing], [class];
我收到以下错误消息。注意 6F Full Form
是我编写的查询,我正尝试在子查询中使用它。
Syntax error in query expression '[runner name] IN (SELECT [runner name] from 6F Full Form WHERE [ratio] >9
试试这个:
(SELECT [runner name]
FROM [6F Full Form]
WHERE [ratio] >9
ORDER BY [runner name], [race ID], [date], [placing], [class]);
您当前 SQL 代码的问题是 field/table/query 包含空格的名称或 reserved words 必须用方括号括起来 - 因此
from 6F Full Form WHERE
应该写成:
from [6F Full Form] WHERE
您的 order by
条款中也可能存在错字:
SELECT ..., [race date], ...
...
ORDER BY ..., [date], ...;
^--------------- Should this be [race date]?
值得补充的是,您也可以使用联接来实现此目的,例如:
select
r.[runner name],
r.[race id],
r.[race date],
r.[placing],
r.[class]
from
runners r inner join
(select distinct f.[runner name] from [6f full form] f where f.[ratio] > 9) q
on r.[runner name] = q.[runner name]
order by
r.[runner name],
r.[race id],
r.[race date],
r.[placing],
r.[class]