【发布时间】:2012-03-30 02:59:31
【问题描述】:
我在名为 bookkeeping 的表中有两列 customer_name 和 invoice_date。
所有已开具发票的客户都会在“invoice_date”列中输入适当的值。 “customer_name”列中的值肯定会有重复,但“invoice_date”列不会(因为一次只有一个客户开具发票)。
假设表中有一个月的数据,我如何从簿记表中获取给定日期的新客户列表。例如,假设表格包含 3 月整个月份的数据,我如何获取在 3 月 17 日首次开具发票的所有客户,不包括在之前(或未来)日期开具发票的所有客户?
我正在使用 Firebird 数据库。
【问题讨论】:
-
这是正确的 SQL 吗?
-
select distinct customer_name from bookkeeping where cast(invoice_date as date) = 'march 29, 2012' and customer_name not in (select distinct customer_name from bookkeeping where cast(invoice_date as date) < 'march 29, 2012');
标签: sql database join firebird