[英]SQL Statement to query average of one column in a table, join and query corresponding column from another table
I have two tables, each set up like this 我有两个表,每个表都这样设置
-------------------------- ---------------------------
| DVD | | Sells |
-------------------------- ---------------------------
| dvdid | title | length | | dvdid | storeid | price |
-------------------------- ---------------------------
| 1 | Alpha | 27 | | 1 | 100 | 11.99 |
-------------------------- ---------------------------
I'm trying to select the average of Sells.price for each DVD.title, and select both. 我正在尝试选择每个DVD.title的Sells.price的平均值,然后选择两者。 Right now I have the following:
现在,我有以下内容:
SELECT AVG(Sells.price), DVD.title
FROM Sells inner join DVD on Sells.dvdid = DVD.dvdid;
Unfortunately this does not work, I receive the error "Not a single-group group function. I assume this means I can't SELECT a function like AVG and then a single column to go along with it. Any ideas? 不幸的是,这行不通,我收到错误消息“不是单组组函数。我认为这意味着我无法选择类似AVG的函数,然后再选择单个列来配合它。有什么想法吗?
You need to add DVD.title
in Group By
您需要在
Group By
依据中添加DVD.title
SELECT AVG(Sells.price), DVD.title
FROM Sells inner join DVD on Sells.dvdid = DVD.dvdid
Group by DVD.title --Here
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.