下面是我的数据和查询,
academic year start date - 2018-01-01
academic year end date - 2018-06-30术语表
term_id parent_id start_date end_date
1 null 2018-01-01 2018-01-30
2 1 2018-01-01 2018-01-10
3 1 2018-01-11 2018-01-20
4 null 2018-02-01 2018-02-28
5 4 2018-02-01 2018-02-10
6 4 2018-02-11 2018-02-20我想添加新学期,它不应该在term_id 1,2的日期范围内,也不应该在学年开始和结束日期的日期范围内。但在我的查询中它不起作用下面是我的查询,
我已经录入,不应该从下面查询录入
start_date - 2018-02-11
end_date - 2018-02-25
SELECT * from term
where parent_id=null
and start_date >= 2018-02-11
and end_date <= 2018-02-25
and start_date >= 2018-01-01(academic year start date)
and end_date <= 2018-06-30(academic year end date)输入子术语相同,应在父术语日期范围内,且在同一父术语的所有子术语中唯一。我已经进入了,这不应该进入,
start_date - 2018-02-13
end_date -2018-02-18我的问题如下,
SELECT * from term
where parent_id=4
and start_date >= 2018-02-13
and end_date <= 2018-02-18
and start_date >= 2018-02-01(parent term start date)
and end_date <= 2018-02-28(parent term end_date)
and start_date >= 2018-01-01(academic year start date)
and end_date <= 2018-06-30(academic year end date)发布于 2018-04-05 02:00:57
好的,所以我要问这个:你的列名是start_date还是start_time?
离开下面,因为仍然相关
日期在SQL语句中使用,就像字符串一样,所以必须用双引号"将它们括起来。因此,您查询应该是这样的:
SELECT * from term
where parent_id=4
and start_date >= "2018-02-13"
and end_date <= "2018-02-18"
and start_date >= "2018-02-01"
and end_date <= "2018-02-28"
and start_date >= "2018-01-01"
and end_date <= "2018-06-30"但是,您的SQL语句非常复杂。你说的是start_date大于2月13日,大于2月1日,大于1月1日,与结束日期相同。
你可以简单地说:
SELECT * FROM term
WHERE parent_id = 4
AND start_date >= "2018-01-01"
AND end_date <= "2018-06-30"这将完成上面所有的"AND“语句。
https://stackoverflow.com/questions/49657456
复制相似问题