简体   繁体   English

MySql-查询如何编写嵌套条件?

[英]MySql - Query How to write nested condition?

I have a table name : allocate_rooms has id, room_id, startTime, endTime. 我有一个表名:allocate_rooms具有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 现在,我必须找到结果应该返回零的查询,这意味着用户将输入输入为房间ID,startTime和endTime,并且应该检查在room_id中是否有任何startTime和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. 例如:如果有人给房间名称指定为星期日,startTime为12:00:00,endTime为12:30:00,它将检查星期日是否有任何startTime和endTime。但是如果他给房间名称为Monday,用户可以保存输入。

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 据我了解,您需要01作为输出,请尝试以下查询

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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