我想查询表“unique_delivery_locations”中的所有条目,其中“transaction_identifier”相同,并且我们在同一个月内。唯一的区别应该是“delivery_start_date”和“delivery_end_date”。这些在同一个月内可能会有所不同,有些会在月初开始,有些会在月中开始。 我尝试了以下续集,但出现错误:
ORA-00904:“月份”:标识符无效
SELECT *
FROM unique_delivery_locations
WHERE transaction_identifier IN (
SELECT transaction_identifier
FROM unique_delivery_locations
WHERE MONTH(delivery_start_date) = MONTH(delivery_end_date)
GROUP BY transaction_identifier
HAVING COUNT(DISTINCT MONTH(delivery_start_date)) > 1
);
据我了解,当
unique_delivery_locations
与delivery_start_date
是同一个月时,您需要来自delivery_end_date
的所有记录。如果是这样,您应该尝试以下代码:
SELECT
*
FROM
unique_delivery_locations t1
WHERE
trunc(t1.delivery_start_date, 'mm') = trunc(t1.delivery_end_date, 'mm')