gpt4 book ai didi

mysql - 查找满足表中存在的某些日期约束的行

转载 作者:行者123 更新时间:2023-11-28 23:20:27 24 4
gpt4 key购买 nike

我有一张这样的 table

CustomerId     serviceID             from                           To
id1 serv1 '2016-01-01 07:22:33' '2016-01-05 07:22:33'
id1 serv1 '2016-02-21 08:30:10' '2016-02-27 08:30:10'
id1 serv2 '2016-02-15 18:30:10' '2016-02-15 19:30:10'
id1 serv3 '2016-02-19 18:30:10' '2016-02-19 19:30:10'
id1 serv4 '2017-01-01 08:30:10' '2017-01-01 09:00:10'

哪里:

 serv1 = "in Dog Hospital"
serv2 = "X ray service"
serv3 = "Recovering meal"

对于报告,我需要找到所有暗示“狗”在“狗医院”接受该服务的那些行,即在狗在“狗医院”期间接受的那些服务。有什么建议吗?

最佳答案

您可以像这样检查不属于 serv1 期间的行:

select *
from t a
where exists (
select 1
from t b
where serviceId = 'serv1'
and a.`from` >= b.`from`
and a.`to` <= b.`to`
);

Demo @ SQLFiddle

关于mysql - 查找满足表中存在的某些日期约束的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41899248/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com