【发布时间】:2016-11-11 01:59:56
【问题描述】:
我需要列出作者的名字、姓氏和已售出的图书总数。所以实际上我需要将 au_id 连接到 title_id 然后连接与他们所写书籍相对应的销售额的 SUM(qty)。
我需要内部加入吗?我觉得这是我得到错误的地方。 谢谢
表: 作者表
+-------+----------+----------+
| au_id | au_fname | au_lname |
+-------+----------+----------+
标题作者表
+-------+---------
| au_id |title_id|
+-------+---------
销售表
+-------+---------
| title_id | QTY |
+-------+---------
查询:
SELECT au_fname, au_lname, TOT FROM(
SELECT au_fname, au_lname FROM authors
INNER JOIN titleauthors ON authors.au_id = titleauthors.au_id
INNER JOIN sales on titleauthors.title_id = sales.title_id WHERE titleauthors.title_id IN(
SELECT sales.title_id, SUM(sales.qty) TOT from sales
group by sales.title_id)) as t
错误:
Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.
Msg 207, Level 16, State 1, Line 29
Invalid column name 'TOT'.
【问题讨论】: