使用子查询连接内连接不支持的表达式

时间:2010-07-05 18:21:30

标签: ms-access

在Access 2003中,我得到了一个“不支持连接表达式”的例外:

SELECT ID FROM Recipes INNER JOIN 
   (SELECT RecID, COUNT(RecID) AS NumIngredients 
    FROM Ingredients GROUP BY RecID) 
ON RecID = ID

我有两张桌子,食谱和配料。 Recipes.ID对应于外键Ingredients.RecID。我想获得与食谱中每行对应的成分中的行数。建议?

2 个答案:

答案 0 :(得分:2)

尝试不加入子查询:

SELECT 
  r.ID AS RecID,
  COUNT(i.ID) AS NumIngredients
FROM 
  Recipes r
  INNER JOIN Ingredients i ON i.RecID = r.ID
GROUP BY
  r.ID

这有用吗?

答案 1 :(得分:0)

SELECT R.ID, COUNT(I.ID) AS CountOfIngredientRecords
FROM Recipes R INNER JOIN Ingredients I
ON R.ID = I.RecID
GROUP BY R.ID