所以我有这两个表,其中包含以下列:
代表身份证明 代表名称
交易ID 价钱 REPID
我希望所有拥有交易的代表共有一个平均数(200)。
是吗:
SELECT * from Reps
INNER JOIN Transactions
ON Reps.Rep ID = Transactions.RepId
WHERE Transactions.Price>(SELECT AVG(200) FROM Transactions);
谢谢!
答案 0 :(得分:2)
您似乎希望让Reps的平均值Price
超过200
:
SELECT RepID
FROM Reps
INNER JOIN Transactions
ON Reps.RepID = Transactions.RepId
GROUP BY RepID
HAVING AVG(Price) > 200
答案 1 :(得分:0)
select r.repid
from reps r,
(select avg(price),repid from transactions group by repid having avg(price)>200) t
where r.repid=t.repid