
# 简单表达式
#### 逻辑表达式
逻辑表达式的操作符和运算规则，请参见[逻辑操作符](https://support.huaweicloud.com/centralized-devg-v2-gaussdb/gaussdb_42_0286.html#ZH-CN_TOPIC_0000002221496169)。
#### 比较表达式
常用的比较操作符，请参见[比较操作符](https://support.huaweicloud.com/centralized-devg-v2-gaussdb/gaussdb_42_0287.html#ZH-CN_TOPIC_0000002221381721)。
除比较操作符外，还可以使用以下句式结构：
- BETWEEN操作符 a BETWEEN x AND y等效于a \>= x AND a \<= y
  a NOT BETWEEN x AND y等效于a \< x OR a \> y
  
- 检查一个值是不是null，可使用： expressionIS NULL
  expression IS NOT NULL
  或者与之等价的句式结构，但不是标准的：
  expression ISNULL
  expression NOTNULL
  ![](https://support.huaweicloud.com/centralized-devg-v2-gaussdb/public_sys-resources/notice_3.0-zh-cn.png)
  不要写expression=NULL或expression\<\>(!=)NULL，因为NULL代表一个未知的值，不能通过该表达式判断两个未知值是否相等。
  
 
- is distinct from/is not distinct from
  - is distinct from A和B的数据类型、值不完全相同时为true。
    A和B的数据类型、值完全相同时为false。
    将空值视为相同。
    
  
  - is not distinct from A和B的数据类型、值不完全相同时为false。
    A和B的数据类型、值完全相同时为true。
    将空值视为相同。
    
   
#### 伪列
ROWNUM
ROWNUM是一个伪列，它返回一个数字，表示从查询中获取结果的行编号。第一行的ROWNUM为1，第二行的为2，以此类推，ROWNUM的返回类型为BIGINT。ROWNUM可以用于限制查询返回的总行数，例如下面语句限制查询从Students表中返回最多10条记录。
```
openGauss=# CREATE TABLE Students (name varchar(20), id int) with (STORAGE_TYPE = USTORE);
openGauss=# INSERT INTO Students VALUES ('Jack', 35);
openGauss=# INSERT INTO Students VALUES ('Leon', 15);
openGauss=# INSERT INTO Students VALUES ('James', 24);
openGauss=# INSERT INTO Students VALUES ('Taker', 81);
openGauss=# INSERT INTO Students VALUES ('Mary', 25);
openGauss=# INSERT INTO Students VALUES ('Rose', 64);
openGauss=# INSERT INTO Students VALUES ('Perl', 18);
openGauss=# INSERT INTO Students VALUES ('Under', 57);
openGauss=# INSERT INTO Students VALUES ('Angel', 101);
openGauss=# INSERT INTO Students VALUES ('Frank', 20);
openGauss=# INSERT INTO Students VALUES ('Charlie', 40);
-- 输出表Students前10行数据。
openGauss=# SELECT * FROM Students WHERE rownum <= 10; 
 name  | id  
-------+-----
 Jack  |  35
 Leon  |  15
 James |  24
 Taker |  81
 Mary  |  25
 Rose  |  64
 Perl  |  18
 Under |  57
 Angel | 101
 Frank |  20
(10 rows)
openGauss=# DROP TABLE Students;
DROP TABLE
```
#### 示例
```
openGauss=# SELECT 2 BETWEEN 1 AND 3 AS RESULT;
 result 
----------
 t
(1 row)
openGauss=# SELECT 2 >= 1 AND 2 <= 3 AS RESULT;
 result 
----------
 t
(1 row)
openGauss=# SELECT 2 NOT BETWEEN 1 AND 3 AS RESULT;
 result 
----------
 f
(1 row)
openGauss=# SELECT 2 < 1 OR 2 > 3 AS RESULT;
 result 
----------
 f
(1 row)
openGauss=# SELECT 2+2 IS NULL AS RESULT;
 result 
----------
 f
(1 row)
openGauss=# SELECT 2+2 IS NOT NULL AS RESULT;
 result 
----------
 t
(1 row)
openGauss=# SELECT 2+2 ISNULL AS RESULT;
 result 
----------
 f
(1 row)
openGauss=# SELECT 2+2 NOTNULL AS RESULT;
 result 
----------
 t
(1 row)
openGauss=# SELECT 2+2 IS DISTINCT FROM NULL AS RESULT;
 result 
----------
 t
(1 row)
openGauss=# SELECT 2+2 IS NOT DISTINCT FROM NULL AS RESULT;
 result  
----------
 f
(1 row)
```
