gpt4 book ai didi

mysql - 生成 sql 查询所需的建议

转载 作者:行者123 更新时间:2023-11-29 23:54:33 25 4
gpt4 key购买 nike

我有一个类似的表,我不知道如何形成像我的预期输出这样的查询

温度 5

id  empid  date
1 E001 11/7
2 E002 11/7
3 E003 11/7
4 E004 11/7
5 E005 11/7
6 E001 12/7
7 E002 12/7
8 E003 12/7
9 E004 12/7
10 E005 12/7
11 E001 13/7
12 E002 13/7
13 E003 13/7
14 E004 13/7
15 E005 13/7

临时6

Id  empid date
1 E001 11/7
2 E002 11/7
3 E005 12/7
4 E001 13/7
5 E004 13/7

温度7

id  date
1 11/7
2 12/7
3 13/7

输出:我期待这些结果

id  empid  date

3 E003 11/7
4 E004 11/7
5 E005 11/7
6 E001 12/7
7 E002 12/7
8 E003 12/7
9 E004 12/7


12 E002 13/7
13 E003 13/7

15 E005 13/7

如何从 temp5 中检索所有员工的值,但不在 temp6 员工 ID 中检索值,并在 temp7 中使用相应的日期。请给我建议。

最佳答案

尝试这样

select t.* from (select temp5.* from temp5 inner join temp7 on 
temp5.da=temp7.da) as t,(select group_concat(empid) as id,
da from temp6 group by da) as t1 where t.da=t1.da and
not find_in_set(t.empid,(t1.id));

Demo

关于mysql - 生成 sql 查询所需的建议,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25439626/

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