什麼dbms?
所以你有這樣的桌子?
CREATE TABLE something
(
pay_period_start date NOT NULL,
pay_period_end date NOT NULL,
CONSTRAINT something_pkey PRIMARY KEY (pay_period_start),
CONSTRAINT something_pay_period_end_key UNIQUE (pay_period_end),
CONSTRAINT something_check CHECK (pay_period_end > pay_period_start)
);
insert into something values ('2010-08-01', '2010-08-14');
insert into something values ('2010-08-15', '2010-08-28');
insert into something values ('2010-08-29', '2010-09-11');
然後我可以運行這個查詢。 (「2010-08-14」是你的止損單柱或結束順序列或類似的東西的價值。)
select * from something
where '2010-08-14' not between pay_period_start and pay_period_end
order by pay_period_start;
,我得到
2010-08-15;2010-08-28
2010-08-29;2010-09-11
對於對日期,使用OVERLAPS操作員。該查詢
select * from something
where
(date '2010-08-01', date '2010-08-14') overlaps
(pay_period_start, pay_period_end)
order by pay_period_start;
回報
2010-08-01;2010-08-14
要排除行,其中啓動順序和結束順序完全匹配一個支付週期,使用這樣的:
select * from something
where (
(date '2010-08-01', date '2010-08-14') overlaps
(pay_period_start, pay_period_end) and
(date '2010-08-01' <> pay_period_start) and
(date '2010-08-14' <> pay_period_end)
)
order by pay_period_start;
好吧,讓我們再試試這個,是有一種方法可以在我使用(其中to_char(start_order,'MM')= to_char(ppd_start)和to_char(end_order,'MM'))之間使用兩個日期(start_order和end_order)字段(ppd_start和ppd_end) = to_char(ppd_end, 'MM')和start_order!= ppd_start和end_order!= ppd_end和start_order不在ppd_start和ppd_end之間,end_order不在ppd_start和ppd_end之間),但它會一直顯示符合ppd_start和ppd_end之間的日期。爲什麼? – Frank 2011-01-21 01:46:52