结合两个地方的陈述

时间:2018-04-30 17:29:03

标签: sql standard-sql

我在将以下两个陈述合并时遇到困难。我需要查询语句1或语句2.我无法弄清楚如何在两者之间添加OR语句。 #标准-SQL

声明1

WHERE
   (feedback IS NOT NULL OR text IS NOT NULL)
   AND rating <= 2

声明2

WHERE
   (rating = 3 OR rating = 4)
   AND feedback IS NOT NULL

理想的结果是这样的......

WHERE
   (feedback IS NOT NULL OR text IS NOT NULL)
   AND rating <= 2
 OR  
   (rating = 3 OR rating = 4)
   AND feedback IS NOT NULL

1 个答案:

答案 0 :(得分:2)

在括号中封装两个完整条件:

WHERE
 (
   (feedback IS NOT NULL OR text IS NOT NULL)
   AND rating <= 2
 )
 OR 
 ( 
   (rating = 3 OR rating = 4)
   AND feedback IS NOT NULL
 )