当使用案例检查列是否超过0时获取语法错误,否则使用其他列

发布于 2025-02-14 00:48:44 字数 1399 浏览 0 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

简单爱 2025-02-21 00:48:44

我认为您不需要案例语句,一切都可以在一个查询中具有某种逻辑:

SELECT *
FROM product_variants
WHERE discount_price >= 60
OR (discount_price <= 0 AND price >= 60)

假设discod_price不能为负,第二个条件可以是(discount_price = 0 and Price&gt; = 60)

编辑:AS @tim biegeleisen 说明,(discount_price&gt; 0 and distib_price&gt; = 60)修复了。

I think you don't need a case statement, everything could be in one query with some logic:

SELECT *
FROM product_variants
WHERE discount_price >= 60
OR (discount_price <= 0 AND price >= 60)

Assuming discount_price cannot be negative, the second condition can be (discount_price = 0 AND price >= 60).

EDIT: As @Tim Biegeleisen stated, (discount_price > 0 AND discount_price >= 60) has no sense, fixed that.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文