我想以有效的方式进行查询,我想知道我该怎么做才能使它更短,或者其他任何其他方法来进行相同的查询?
这是我的表格
create table EmpTable (
id int,
task varchar(10),
startDate varchar,
endDate varchar
)
,我正在插入我的(ID,任务,启动时间和末日
insert into EmpTable
select
1,'Task A', '2018-01-10 10:00:00', '2018-01-10 12:00:00';
insert into EmpTable
select
2,'Task B', '2018-01-10 11:30:00', '2018-01-10 16:00:00';
insert into EmpTable
select
3,'Task C', '2018-01-10 08:30:00', '2018-01-10 09:00:00';
insert into EmpTable
select
4,'Task D', '2018-01-10 09:00:00', '2018-01-10 15:00:00';
insert into EmpTable
select
5,'Task E', '2018-01-10 08:00:00', '2018-01-10 20:00:00';
用来更新表更新表的
UPDATE EmpTable
SET starttime = '2018-01-11 9:00:00', endtime = '2018-01-11 9:30:00'
WHERE id = 2;
select * from EmpTable;
select *
from EmpTable as t1, EmpTable as t2
where t1.id = 1 and t2.id = 2;
情况,这是我使用的情况,用于获取详细信息,无论是否有任何插槽重叠。
select
case when
(t1.starttime between t2.starttime and t2.endtime) or
(t1.endtime between t2.starttime and t2.endtime) or
(t2.starttime between t1.starttime and t1.endtime) or
(t2.endtime between t1.starttime and t1.endtime)
then
'yes'
else
'no'
end as OverLapping
from EmpTable as t1, EmpTable as t2
where t1.id = 1 and t2.id = 3
This is my Table
create table EmpTable (
id int,
task varchar(10),
startDate varchar,
endDate varchar
)
Here I am inserting my (id, task, starttime, and endtime
insert into EmpTable
select
1,'Task A', '2018-01-10 10:00:00', '2018-01-10 12:00:00';
insert into EmpTable
select
2,'Task B', '2018-01-10 11:30:00', '2018-01-10 16:00:00';
insert into EmpTable
select
3,'Task C', '2018-01-10 08:30:00', '2018-01-10 09:00:00';
insert into EmpTable
select
4,'Task D', '2018-01-10 09:00:00', '2018-01-10 15:00:00';
insert into EmpTable
select
5,'Task E', '2018-01-10 08:00:00', '2018-01-10 20:00:00';
used this to update the table
UPDATE EmpTable
SET starttime = '2018-01-11 9:00:00', endtime = '2018-01-11 9:30:00'
WHERE id = 2;
select * from EmpTable;
select *
from EmpTable as t1, EmpTable as t2
where t1.id = 1 and t2.id = 2;
this is my case which I am using for getting the details whether any slot getting overlaps or not.
select
case when
(t1.starttime between t2.starttime and t2.endtime) or
(t1.endtime between t2.starttime and t2.endtime) or
(t2.starttime between t1.starttime and t1.endtime) or
(t2.endtime between t1.starttime and t1.endtime)
then
'yes'
else
'no'
end as OverLapping
from EmpTable as t1, EmpTable as t2
where t1.id = 1 and t2.id = 3
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论