2015-11-05 30 views
-1

我猜基本組中被卡住了。Sql服務器:選擇兩個日期之間的日期和顯示包括重複的所有結果

select date,* from table 

這是返回我約7000行。

假設分鐘(日期)是 '1989年5月12日' 和max(日期)是 '2005年5月12日',然後

select * from table where date between '1989-5-12' and '2005-5-12' 

它返回我周圍6000行。 剩餘的行在哪裏?我怎樣才能得到完整的結果(7000行)與日期之間的where子句。

+0

爲什麼MySQL的標籤,是不是這樣的產品參與? – jarlh

+1

列日期的數據類型? VARCHAR ???如果是這種情況,請按照日期進行投射。 (1989-5-12是無效的日期字面...) – jarlh

+0

嘗試**投(日期爲日期)** –

回答

2

很明顯,你有NULL在你的數據:

select * from table 
where date between '1989-5-12' and '2005-5-12' or date is null 

樣品表:

('20150101'), 
(null), 
('20150102'), 
('20150103'), 
(null) 

select * from table --will return 5 rows 

select * from table 
where date between '20150101' and '20150103' --will return 3 rows 

select * from table 
where date not between '20150101' and '20150103' --will return 0 rows 
+0

是的,我現在明白了,謝謝你 – Abhii

0

其餘行不適合你的where語句。要查看剩餘的行只是做:

select * from table where date NOT between '1989-5-12' and '2005-5-12' 

沒有任何數據,我們不能說你爲什麼不從你的SELECT語句中得到它們。

相關問題