简体   繁体   中英

how to add dynamic data based on condition in mysql

groupId  scduleDate
1        '2016-10-5 10:30:00'
2        '2016-10-4 10:30:00'
3        '2016-10-19 10:30:00'
4       '2016-10-19 10:30:00' 

This is my Table i have to fetch one column dynamically based on Condition

i am trying using this but i am unable to get Value

select groupId,scduleDate
,
case scheduledDate when  >now  then "1"
    else '0'
end
as Real_Title 
from EventList_View

my Expected Output is like this :

groupId  scduleDate                status
1        '2016-10-5 10:30:00'     0
2        '2016-10-4 10:30:00'     0
3        '2016-10-19 10:30:00'    1
4       '2016-10-19 10:30:00'      1

I want-to apply Condition based today date and previous date accordingly i want to add status if previous date from today date it should 0 else 1 but when i try to execute my query nothing data come please tell me where am doing wrong .

You have syntax error in your CASE expression.

Query

select groupId,scduleDate,
case when scduleDate > now()  then 1 else 0 end as Real_Title 
from EventList_View;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM