简体   繁体   English

SQL:非单组群 function

[英]SQL: not a single-group group function

I am writing a SQL statement through VBA.我正在通过 VBA 编写 SQL 语句。 When typing in the product origin in a textbox, it will retrieve all product IDs from the same origin and their average price.在文本框中输入产品来源时,它将检索来自同一来源的所有产品 ID 及其平均价格。 Below is my SQL statement:以下是我的 SQL 声明:

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

It gives me an error SQL: not a single-group group function.它给了我一个错误 SQL: not a single-group group function。 How can I fix this error?我该如何解决这个错误?

Your PRO_ORIGIN condition should be in a WHERE clause, and you should be grouping by PRO_ID :您的PRO_ORIGIN条件应该在WHERE子句中,并且您应该按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) .另外你有一个错字, AVG(PRO_PRICE_应该是AVG(PRO_PRICE)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM