简体   繁体   中英

MySql - Query How to write nested condition?

I have a table name : allocate_rooms has id, room_id, startTime, endTime.

now I have to find the Query where result should be return zero Means user will give input as room id and startTime and endTime and it should check whether in that room_id there is any startTime and endTime

Eg: if someone give room name as sunday and startTime as 12:00:00 and endTime as 12:30:00 it will check whether in sunday there is any startTime and endTime But if he give room name as Monday user can save the input.

SELECT id FROM allocate_rooms
         where startTime='12:00:00' and endTime=' 12:30:00' AND day_id = 'sunday'

I have written the Query but it's not working properly. How do I write the exact query?

From what I understand you need 0 or 1 as output, try the below query

SELECT ifnull (id, 0, 1)
FROM allocate_rooms
WHERE startTime='12:00:00' or endTime=' 12:30:00'
     AND day_id = 'sunday'

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