2015-09-12 288 views
0

我的表是這樣的:SQL日期查詢生日

+----------+------------+ 
| name  | birthday | 
+----------+------------+ 
| jean  | 1988-08-09 | 
| andrew | 1990-09-20 | 
| jennifer | 1980-09-05 | 
| Harry | 1985-10-25 | 
| Chris | 1987-09-22 | 
+----------+------------+ 

我想表明從生日表,其中的生日就在九月和日期間4月21日這樣的結果:

+----------+------------+ 
| name  | birthday | 
+----------+------------+ 
| andrew | 1990-09-20 | 
| jennifer | 1980-09-05 | 
+----------+------------+ 

有人可以幫我嗎?

回答

1
SELECT name, 
     birthday 
FROM T 
WHERE MONTH(birthday) = 9 
AND DAY(birthday) > 4 
AND DAY(birthday) < 21; 
+0

我可以添加更多的條件,4和21這樣我就可以得到安德魯和詹妮弗之間,像日期? – FrankPho

+0

絕對。將'AND DAY(birthday)> = 4 AND DAY(birthday)<= 21'添加到該查詢的末尾。如果您將問題更新爲包含該問題,我會將其添加到我的答案中。 –

+0

done編輯它.. :) 非常感謝你... – FrankPho

0
SELECT NAME,BIRTHDAY 
FROM YOURTABLE 
WHERE MONTH(BIRTHDAY)=9 AND DAY(BIRTHDAY) BETWEEN 4 AND 21