📜  Teradata-逻辑和条件运算符

📅  最后修改于: 2020-11-29 08:57:44             🧑  作者: Mango


Teradata支持以下逻辑和条件运算符。这些运算符用于执行比较并组合多个条件。

Syntax Meaning
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to
= Equal to
BETWEEN If values within range
IN If values in
NOT IN If values not in
IS NULL If value is NULL
IS NOT NULL If value is NOT NULL
AND Combine multiple conditions. Evaluates to true only if all conditions are met
OR Combine multiple conditions. Evaluates to true only if either of the conditions is met.
NOT Reverses the meaning of the condition

之间

BETWEEN命令用于检查值是否在值范围内。

考虑以下雇员表。

EmployeeNo FirstName LastName JoinedDate DepartmentNo BirthDate
101 Mike James 3/27/2005 1 1/5/1980
102 Robert Williams 4/25/2007 2 3/5/1983
103 Peter Paul 3/21/2007 2 4/1/1983
104 Alex Stuart 2/1/2008 2 11/6/1984
105 Robert James 1/4/2008 3 12/1/1984

下面的示例获取员工编号在101,102到103之间的记录。

SELECT EmployeeNo, FirstName FROM  
Employee 
WHERE EmployeeNo BETWEEN 101 AND 103;

执行上述查询时,它返回员工编号在101到103之间的员工记录。

*** Query completed. 3 rows found. 2 columns returned. 
*** Total elapsed time was 1 second. 
 EmployeeNo            FirstName 
-----------  ------------------------------ 
   101                   Mike 
   102                   Robert 
   103                   Peter

IN命令用于根据给定的值列表检查值。

以下示例获取员工编号为101、102和103的记录。

SELECT EmployeeNo, FirstName FROM  
Employee 
WHERE EmployeeNo in (101,102,103);

上面的查询返回以下记录。

*** Query completed. 3 rows found. 2 columns returned. 
*** Total elapsed time was 1 second.  
 EmployeeNo            FirstName 
-----------  ------------------------------ 
   101                   Mike 
   102                   Robert 
   103                   Peter

不在

NOT IN命令反转IN命令的结果。它获取值与给定列表不匹配的记录。

以下示例获取员工编号不在101、102和103中的记录。

SELECT * FROM  
Employee 
WHERE EmployeeNo not in (101,102,103);

上面的查询返回以下记录。

*** Query completed. 2 rows found. 6 columns returned. 
*** Total elapsed time was 1 second. 
 EmployeeNo          FirstName                      LastName 
----------- ------------------------------ -----------------------------    
    104                Alex                          Stuart 
    105                Robert                        James