请注意,我不是开发人员,因此在这里提供任何帮助将不胜感激。
我的问题: 我在Oracle Responsys中有一个列表,其中包含所有在旅行中预订的客户。我想查找所有缺少FIRST_NAME值(可能是Tba / Tbc / Null)的记录,因此我可以向主预订者发送电子邮件,要求他们更新其他客人的姓名详细信息。
主预订者将始终具有以'-1'结尾的CUSTOMER_ID_值。缺少名字值的记录将不会。
我想做的是,从列表中选择所有缺少名字的记录,并按BOOKING_LOCATOR(主要预订者及其附加来宾共享的值)对它们进行分组-然后仅返回主要预订者( CUSTOMER_ID_以'-1'结尾的记录。
到目前为止,我通过查看其他帖子已经大致了解了Im,但是它并没有返回我所追求的东西:
SELECT $A$.BOOKING_LOCATOR, $A$.CUSTOMER_ID_, $A$.EMAIL_ADDRESS_
FROM
(
SELECT $A$.BOOKING_LOCATOR FROM $A$ WHERE ($A$.FIRST_NAME IN ('TBA', 'TBC', 'Tba', 'Tbc') OR $A$.FIRST_NAME IS NULL) AND $A$.POLAR_BOOKING_STATUS != 'C' AND $A$.BOOKING_STATUS != 'Waitlist' AND $A$.EMBARK_DATE >= SYSDATE+1
GROUP BY $A$.BOOKING_LOCATOR
) $A$
INNER JOIN (
SELECT $A$.BOOKING_LOCATOR AS BOOKINGNUM, $A$.CUSTOMER_ID_, $A$.EMAIL_ADDRESS_ FROM $A$ WHERE $A$.CUSTOMER_ID_ LIKE '%-1'
) $A$ ON $A$.BOOKING_LOCATOR = $A$.BOOKINGNUM
有人可以指引我正确的方向吗?
答案 0 :(得分:2)
为子选择项命名:
summary =
答案 1 :(得分:1)
是的,可以做到。您可以为此使用Joins或OUTER APPLY。
SELECT A.BOOKING_LOCATOR, B.CUSTOMER_ID_, B.EMAIL_ADDRESS_
FROM
(
SELECT $A$.BOOKING_LOCATOR FROM $A$ WHERE ($A$.FIRST_NAME IN ('TBA', 'TBC', 'Tba',
'Tbc') OR $A$.FIRST_NAME IS NULL) AND $A$.POLAR_BOOKING_STATUS != 'C' AND
$A$.BOOKING_STATUS != 'Waitlist' AND $A$.EMBARK_DATE >= SYSDATE+1
GROUP BY $A$.BOOKING_LOCATOR
) A
INNER JOIN (
SELECT $A$.BOOKING_LOCATOR AS BOOKINGNUM, $A$.CUSTOMER_ID_, $A$.EMAIL_ADDRESS_ FROM
$A$ WHERE $A$.CUSTOMER_ID_ LIKE '%-1'
) B ON A.BOOKING_LOCATOR = B.BOOKINGNUM;
-2ND选项是通过使用OuterAPPLY来实现的。
SELECT A.BOOKING_LOCATOR, B.CUSTOMER_ID_, B.EMAIL_ADDRESS_
FROM
(
SELECT $A$.BOOKING_LOCATOR FROM $A$ WHERE ($A$.FIRST_NAME IN ('TBA', 'TBC', 'Tba',
'Tbc') OR $A$.FIRST_NAME IS NULL) AND $A$.POLAR_BOOKING_STATUS != 'C' AND
$A$.BOOKING_STATUS != 'Waitlist' AND $A$.EMBARK_DATE >= SYSDATE+1
GROUP BY $A$.BOOKING_LOCATOR
) A
Outer APPLY(
SELECT $A$.BOOKING_LOCATOR AS BOOKINGNUM, $A$.CUSTOMER_ID_, $A$.EMAIL_ADDRESS_ FROM
$A$ WHERE $A$.CUSTOMER_ID_ LIKE '%-1'
) B ON A.BOOKING_LOCATOR = B.BOOKINGNUM;
答案 2 :(得分:1)
如果您想要预订的地点和主要客户,那么EXISTS
就会浮现在脑海:
SELECT . . . -- whatever columns you want
FROM $A$ a1
WHERE a.CUSTOMER_ID_ LIKE '%-1' AND
EXISTS (SELECT 1
FROM $A$ a
WHERE a.FIRST_NAME IN ('TBA', 'TBC', 'Tba', 'Tbc') OR a.FIRST_NAME IS NULL) AND
a.POLAR_BOOKING_STATUS <> 'C' AND
a.BOOKING_STATUS <> 'Waitlist' AND
a.EMBARK_DATE >= SYSDATE+1 AND
a.BOOKING_LOCATOR = a1.BOOKING_LOCATOR
);
每个主要客户只返回一行。