答案 0 :(得分:1)
您的查询是在正确的轨道上。您只需修复SQL错误:
SELECT a.vendor, a.part_nr, a.delivery_time, b.avr_del_time
FROM Table1 as a INNER JOIN
(SELECT vendor, part_nr, AVG(delivery_time) AS avr_del_time
FROM Table1
GROUP BY vendor, part_nr
) as b
ON a.vendor = b.vendor AND a.part_nr = b.part_nr;
注意:
GROUP BY
子查询中,您需要SELECT
中的密钥。ON
条件下有逗号;它应该是AND
。答案 1 :(得分:0)
您需要在子查询中返回已连接的字段,或者无法继续工作
SELECT a.vendor, a.part_nr, a.delivery_time, b.avr_del_time
FROM Table1 a
INNER JOIN (SELECT Vendor,
part_nr,
AVG(delivery_time) AS avr_del_time
FROM Table1
GROUP BY vendor, part_nr) b
ON a.vendor = b.vendor and a.part_nr=b.part_nr
答案 2 :(得分:0)
除了JOIN ON
条件
ON a.vendor = b.vendor
AND a.part_nr=b.part_nr // OR condition can as well be based on requirement
此外,因为它是一个计算值,所以在从表中添加单独的列时没有任何意义,而是在从表中获取时在显示结果中使用该列