gpt4 book ai didi

mysql - 如果在表 2 中找不到引用,将从表 1 中删除记录的查询

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

table1
refno status
1 A
2 A
6 A
3 A

table2
refno itemcode qty
1 1 5
1 2 0
3 8 0
3 1 0
2 4 3
6 7 0

我需要一个查询,如果在 [table2] 中找不到 [refno],则同时删除 [table2] 中 qty=0 的所有行将删除 [table1] 中的行

鉴于上述示例,查询应保留以下输出:

table1
refno status
1 A
2 A

table2
refno itemcode qty
1 1 5
2 4 3

谢谢

最佳答案

你可以在一个事务中写 2 个 delete 语句来确保它是一个原子操作。

关于mysql - 如果在表 2 中找不到引用,将从表 1 中删除记录的查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12670277/

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