Oracle SQL内部联接

时间:2014-12-06 17:49:08

标签: sql oracle

我有以下查询,工作正常。

SELECT  c.id, c.customer_name, b.batch_prefix, b.BatchCount, b.InvoiceCount, e.time_of_delivery, e.time_of_delivery_mail, e.time_of_delivery_clock
FROM koll_customers c
INNER JOIN (
SELECT batch_prefix, COUNT(*) AS BatchCount,
SUM (batch_counter) AS InvoiceCount
FROM koll_batchlogs
WHERE
          exists_db = 0
          and is_checked = 1
         and batch_counter > 0
         and trunc(created_date) > trunc(sysdate-7)
GROUP BY batch_prefix) b
ON b.batch_prefix=c.customer_prefix
INNER JOIN koll_customer_export e
ON c.id = e.id

但是,当我使用SELECT和WHERE添加另一个JOIN(最后一个连接)时,它会给出错误:“无效的标识符”

SELECT  c.id, c.customer_name, b.batch_prefix, b.BatchCount, b.InvoiceCount
FROM koll_customers c
INNER JOIN (
SELECT batch_prefix, COUNT(*) AS BatchCount,
SUM (batch_counter) AS InvoiceCount
FROM koll_batchlogs
WHERE
          exists_db = 0
          and is_checked = 1
         and batch_counter > 0
         and trunc(created_date) > trunc(sysdate-7)
GROUP BY batch_prefix) b
ON b.batch_prefix=c.customer_prefix
INNER JOIN (
     SELECT time_of_delivery
     FROM koll_customer_export
     WHERE time_of_delivery=2) e
 ON e.id = c.id

我想知道,最后一次加入有什么问题?

2 个答案:

答案 0 :(得分:0)

这是join

INNER JOIN
(SELECT time_of_delivery
 FROM koll_customer_export
 WHERE time_of_delivery=2
) e
ON e.id = c.id

您指的是e.id,但您在子查询中没有这个。试试这个:

INNER JOIN
(SELECT time_of_delivery, id
--------------------------^
 FROM koll_customer_export
 WHERE time_of_delivery=2
) e
ON e.id = c.id

答案 1 :(得分:0)

 INNER JOIN (
 SELECT time_of_delivery
 FROM koll_customer_export
 WHERE time_of_delivery=2) e
 ON e.id = c.id

没有名为id的列。