SQL:不是单组组函数

我正在通过VBA编写SQL语句。在文本框中输入产品来源时,它将检索来自相同来源的所有产品ID及其平均价格。以下是我的SQL语句:

SQL = "SELECT PRO_ID, AVG(PRO_PRICE_ " & _
      "FROM PRODUCT " & _
      "GROUP BY PRO_ORIGIN = '" & Label1.Value & "'"

它给我一个错误SQL:不是单组分组函数。如何解决此错误?

评论
Alex55
Alex55

Your PRO_ORIGIN condition should be in a WHERE clause, and you should be grouping by PRO_ID:

SQL = "SELECT PRO_ID, AVG(PRO_PRICE) " & _
      "FROM PRODUCT " & _
      "WHERE PRO_ORIGIN = '" & Label1.Value & "' " & _
      "GROUP BY PRO_ID"

Also you have a typo, AVG(PRO_PRICE_ should be AVG(PRO_PRICE).

点赞
评论