sql使用Count(*)函数

时间:2016-04-25 08:30:33

标签: sql ms-access count

我正在使用Microsoft Access 2013和 我想在每家咖啡馆找到订单数量,但显示的数字是错误的。 这是我的代码:

SELECT Avg(Feedback.RatingForExperience) AS caferating,
      Count(tblOrder_Product.ProductCode) AS cafesales, Feedback.cafeid
FROM tblOrder_Product, Feedback
GROUP BY Feedback.cafeid;

请帮帮我,谢谢。

enter image description here Screen1

[]

1 个答案:

答案 0 :(得分:1)

如评论中所述,您需要将表格加在一起。下面是SQL。

SELECT Avg(Feedback.RatingForExperience) AS caferating,
  Count(tblOrder_Product.ProductCode) AS cafesales, Feedback.cafeid
FROM tblOrder_Product INNER JOIN Feedback ON tblOrder_Product.OrderCode = Feedback.OrderCode
GROUP BY Feedback.cafeid;

或者

SELECT Avg(Feedback.RatingForExperience) AS caferating,
  Count(tblOrder_Product.ProductCode) AS cafesales, Feedback.cafeid
FROM tblOrder_Product LEFT JOIN Feedback ON tblOrder_Product.OrderCode = Feedback.OrderCode
GROUP BY Feedback.cafeid;