开发者

How can I compare different rows of different columns in the same table in MySQL

How can I com开发者_StackOverflow中文版pare different rows of different columns in the same table in MySQL?? I want to get all the data between given Start_Date and End_Date in my database table. But two dates are not in the same row.Ex,

Start_Date    End_Date      Data
2011-07-01    2011-07-31     AA
2011-08-01    2011-08-31     BB

I want to get data between '2011-07-01' and '2011-08-31'.How can I do that? Please reply me with MySQL code.Thanks a lot.


try

where 
Start_Date between  '2011-07-01' and '2011-08-31' 
OR
End_Date between  '2011-07-01' and '2011-08-31'


Are You Want the data between '2011-07-01' and '2011-08-31'. Thats Start_Date is 2011-07-01 or more and End_Date is '2011-08-31' or less.

Am I Correct?. If i correct Try below Query.

SELECT Data FROM table_Name WHERE Start_Date <= '2011-07-01' AND End_Date >= '2011-08-31'

Happy Coding.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜