【问题标题】:Conditional WHERE statement SQL条件 WHERE 语句 SQL
【发布时间】:2022-01-14 18:39:35
【问题描述】:

我正在尝试获取条件 WHERE 语句,但我不确定如何在不使用 CASE WHEN 的情况下执行此操作。

SELECT * FROM
  `...`
WHERE (CASE WHEN product <> 'core news' THEN type <> 'video')
ORDER BY product, metric, type

【问题讨论】:

  • 1) 标记您正在使用的数据库 2) 提供示例数据和所需的输出 3) 为什么不使用案例陈述?
  • CASE 有什么问题?

标签: sql conditional-statements


【解决方案1】:

如果我正确理解你的问题,我相信你想要

SELECT * FROM
  `...`
WHERE product = 'core news' OR (product <> 'core news' AND type <> 'video')
ORDER BY product, metric, type

【讨论】:

  • 是的,非常感谢!
【解决方案2】:

也许你是这个意思

SELECT * 
FROM yourtable
WHERE 
(
     (product <> 'core news' AND type <> 'video') 
  OR (product = 'core news') 
) 
ORDER BY product, metric, type

【讨论】:

    猜你喜欢
    • 2013-03-08
    • 1970-01-01
    • 1970-01-01
    • 2011-05-28
    • 1970-01-01
    • 2011-08-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多