我想比较 where 子句中的两列是否相等。列是两列来自已连接的不同表
这是我正在使用的语句
SELECT authors.state, sum(qty*price)as sales_revenue
from authors,titles, stores, sales
WHERE authors.state = (SELECT stores.state from stores)
但我收到一个错误提示 中号
sg 8120, Level 16, State 1, Line 1
Column 'authors.state' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
最佳答案
使用这个:
WHERE authors.state = stores.state
或者更好的是,使用 ANSI-92 JOIN 语法。
SELECT authors.state, sum(qty*price) as sales_revenue
FROM authors
JOIN stores ON authors.state = stores.state
JOIN titles ON ...
JOIN sales ON ...
GROUP BY authors.state
关于sql - 比较 Where 子句中两列是否相等,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5467660/