gpt4 book ai didi

mysql - mysql表中缺少数据

转载 作者:行者123 更新时间:2023-11-30 22:36:14 26 4
gpt4 key购买 nike

请帮我写这个查询。我试过使用 leftjoin 但它不起作用。

我有两个表tdatetollname。在 tdate 表中我只有日期,比如一个月和第二个表 tollname 我有带日期的通行费名称。

我想找到表 tollname 中缺失的收费日期。

表名:tdate

Dates
1
2
3
4
...

30

收费站

Dates   TollName
1 A
1 B
1 C
5 A
5 B
6 C
9 B
12 A
12 B
12 C
28 A
28 B
30 C

最佳答案

您可以只使用cross joinleft join(或者等同于not exists/not in) .这将生成 tollnamedate 的所有组合,然后返回您的表中不存在的组合:

select d.date, t.tollname
from tdate d cross join
(select distinct tollname from tollname) t
where not exists (select 1
from tollname t2
where d.date = t2.date and t.tollname = t2.tollname
);

如果您有一个包含 tollname 的单独表,那么您可以使用它来代替子查询:

关于mysql - mysql表中缺少数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32470237/

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