gpt4 book ai didi

SQL 查询 where 子句

转载 作者:行者123 更新时间:2023-12-04 17:11:36 25 4
gpt4 key购买 nike

很难说出这里问的是什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或言辞激烈,无法以目前的形式合理回答。如需帮助澄清此问题以便可以重新打开,visit the help center .




9年前关闭。




我的 sql 查询中有这一行:

WHERE client = $id
AND (isinvoiced = 0) OR (isinvoiced = 1 and isrecurring = 1)

得到的结果比我预期的要多。但是,如果我这样写:
WHERE client = $id
AND (isinvoiced = 0) OR (isinvoiced = 1 and isrecurring = 1 and client = $id)

然后它让我得到我想要的结果,但这是写这个的最好方法吗?我只是不想再遇到此代码的任何问题。

最佳答案

您还需要一套 ()围绕整个AND条款。这表明 client = $id必须为真,其他条件之一也必须为真 = isinvoiced = 0isinvoiced = 1 and isrecurring = 1 的组合.

 WHERE client = $id
AND ((isinvoiced = 0) OR (isinvoiced = 1 and isrecurring = 1))

关于SQL 查询 where 子句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10283464/

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