Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a table (DBname) with 2 columns. column1 (datatype =dates) has the dates for the next 2 years. column2 (datatype = integer) some data i've assigned. How can I get SQL to select the data in column2 that corresponds with the current system date. i've tried the following without success it return a blank... I am using MySQL

SELECT column2 FROM DBname WHERE column1 = CURRENT_DATE

if i change it to

SELECT column2 FROM DBname WHERE column1 > CURRENT_DATE

it returns column2 rowid1

if i change it to

SELECT column2 FROM DBname WHERE column1 > CURRENT_DATE

it returns column2 rowid3... really confused... is it possible the problem is in the database itself??

as for the data.. i imported an excel file with the dates in column1.. i wrote the first date in and formatted it then dragged down about 2 years to populate the rest.... as for the column2 data it is just numbers i have placed in... an example would be

column1 1-dec-12, 2-dec-12, 3-dec-12, 4-dec-12     
column2   2,  4, 18, 19  
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
142 views
Welcome To Ask or Share your Answers For Others

1 Answer

I think you column1 which holds date is a STRING. You need first to convert it to DATE using STR_TO_DATE function,

SELECT *
FROM table1
WHERE STR_TO_DATE(column1, '%e-%b-%y') > CURDATE()

OTHER SOURCE


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...