简体   繁体   English

SQL语句可查询表中一列的平均值,并从另一张表中联接并查询相应的列

[英]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.

相关问题 SQL查询联接一列的平均值,其中另一列在另一表的两列值之间 - Sql query join average of one column where another column is between two columns values of another table 如何编写 BigQuery/SQL 查询以将一个表中的列的平均值与第二个/另一个表中的列相除 - How to write BigQuery/SQL query to divide average of a column in one table from column in second/another table SQL-从另一个表获取列以加入此查询 - SQL - Getting a column from another table to join this query 将另一个表中的列添加到现有的SQL /查询语句中 - Adding a column from another table into existing SQL/query statement SQL 查询:将 1 个表中的 2 列与另一个表中的 1 列连接(或选择)以获得没有额外连接列的视图 - SQL Query: Join (or select) 2 columns from 1 table with 1 column from another table for a view without extra join columns sql 查询在一个表列上连接两个表等于另一个表中的某些列 - sql query join two tables on one table column equals to some columns in another table SQL查询-将另一个表中的一个或多个值连接在一起/两次创建同一列/查找当前表的值 - SQL Query - Join one to many values from another table / creating same column twice / look up values for the current table 从一个查询使用ID值,到另一个表中具有相同ID的对应列 - Use id values from one query, to corresponding column with same id in another table SQL查询更新另一个表的引用一个表的列 - SQL query to update column of one table with reference of another table 查询从一个表中汇总金额并按另一表中的列对其进行分组 - Query to sum amounts from one table and group it by a column in another table
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM