我想以有效的方式进行查询,我想知道我该怎么做才能使它更短,或者其他任何其他方法来进行相同的查询?

发布于 2025-01-26 02:53:30 字数 1260 浏览 3 评论 0原文

这是我的表格

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文