gpt4 book ai didi

mysql - 如何正确编写 SQL 查询来选择日期

转载 作者:行者123 更新时间:2023-11-29 16:14:36 25 4
gpt4 key购买 nike

如何写这样的请求。我在数据库中有一个日期(tableName=DateTime),id(tableName=Name)和3个表,其中id的日期位于其中。

enter image description here

我需要选择id,从该id开始的日期不会输入到其他日期。那些。如果第 3 行的日期不在表中,那么我将得到 id=3我是这样写的,但是不正确(

 "select id from Name 
where (select id from Name where id=3
and (date.DateTime not in (select date from DateTime)))"

最佳答案

这是你想要的吗?

select n.id
from name n
where not exists (select 1
from name n2
where n2.date = n.date and n2.id <> n.id
);

等效方法是:

select max(n.id)
from name n
group by n.date
having count(*) = 1;

关于mysql - 如何正确编写 SQL 查询来选择日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54944298/

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