我遇到了一些access97 sql,
SELECT Master.Text, Sub.Cnt
FROM Master
INNER JOIN [
SELECT Number, COUNT(*) As Cnt FROM SubTable GROUP BY Number]. AS Sub
ON Master.Number=Sub.Number
WHERE Master.Number=1;
正如我所期望的那样,我需要在哪里支持“SubTable”'名称我在突出显示GROUP
的FROM子句中收到错误SELECT Master.Text, Sub.Cnt
FROM Master
INNER JOIN [
SELECT Number, COUNT(*) As Cnt FROM [Sub Table] GROUP BY Number]. AS Sub
ON Master.Number=Sub.Number
WHERE Master.Number=1;
有人能指出我正确的方向吗?
由于
答案 0 :(得分:0)
方括号在查询中看起来很奇怪。尝试使用常规括号作为子查询:
SELECT Master.Text, Sub.Cnt
FROM Master INNER JOIN
(SELECT Number, COUNT(*) As Cnt
FROM [Sub Table]
GROUP BY Number
) AS Sub
ON Master.Number = Sub.Number
WHERE Master.Number = 1;
编辑:
您可以将此查询重写为:
SELECT Master.Text, COUNT(*) as Cnt
FROM Master INNER JOIN
[Sub Table] as sub
ON Master.Number = Sub.Number
WHERE Master.Number = 1
GROUP BY Number;