

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 比較運算子
<a name="comparison-operators"></a>

比較條件表示兩個值之間的邏輯關係。所有比較條件都是二元運算子，具有 Boolean 傳回類型。

AWS Clean Rooms Spark SQL 支援下表所述的比較運算子。

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/clean-rooms/latest/sql-reference/comparison-operators.html)

## 範例
<a name="comparison-condition-example"></a>

下列是比較條件的一些簡單範例：

```
a = 5
a < b
min(x) >= 5
qtysold = any (select qtysold from sales where dateid = 1882
```

下列查詢會傳回目前未偽造之所有 squirrel 的 ID 值。

```
SELECT id FROM squirrels 
WHERE !is_foraging
```

下列查詢會從 VENUE 資料表傳回超過 10，000 個座位的場地：

```
select venueid, venuename, venueseats from venue
where venueseats > 10000
order by venueseats desc;

venueid |           venuename            | venueseats
---------+--------------------------------+------------
83 | FedExField                     |      91704
 6 | New York Giants Stadium        |      80242
79 | Arrowhead Stadium              |      79451
78 | INVESCO Field                  |      76125
69 | Dolphin Stadium                |      74916
67 | Ralph Wilson Stadium           |      73967
76 | Jacksonville Municipal Stadium |      73800
89 | Bank of America Stadium        |      73298
72 | Cleveland Browns Stadium       |      73200
86 | Lambeau Field                  |      72922
...
(57 rows)
```

此範例會從 USERS 資料表中，選取喜歡搖滾樂的使用者 (USERID)：

```
select userid from users where likerock = 't' order by 1 limit 5;

userid
--------
3
5
6
13
16
(5 rows)
```

此範例會從 USERS 資料表中，選取不確定是否喜歡搖滾樂的使用者 (USERID)：

```
select firstname, lastname, likerock
from users
where likerock is unknown
order by userid limit 10;

firstname | lastname | likerock
----------+----------+----------
Rafael    | Taylor   |
Vladimir  | Humphrey |
Barry     | Roy      |
Tamekah   | Juarez   |
Mufutau   | Watkins  |
Naida     | Calderon |
Anika     | Huff     |
Bruce     | Beck     |
Mallory   | Farrell  |
Scarlett  | Mayer    |
(10 rows
```

## 具有 TIME 欄的範例
<a name="comparison-condition-example-time"></a>

下列範例資料表 TIME\$1TEST 有一個 TIME\$1VAL 欄 (類型為 TIME)，其中插入了三個值。

```
select time_val from time_test;
            
time_val
---------------------
20:00:00
00:00:00.5550
00:58:00
```

下列範例會擷取每個 timetz\$1val 中的小時數。

```
select time_val from time_test where time_val < '3:00';
   time_val
---------------
 00:00:00.5550
 00:58:00
```

下列範例會比較兩個時間常值。

```
select time '18:25:33.123456' = time '18:25:33.123456';
 ?column?
----------
 t
```

## 具有 TIMTZ 欄的範例
<a name="comparison-condition-example-timetz"></a>

下列範例資料表 TIMETZ\$1TEST 有一個 TIMETZ\$1VAL 欄 (類型為 TIMETZ)，其中插入了三個值。

```
select timetz_val from timetz_test;
            
timetz_val
------------------
04:00:00+00
00:00:00.5550+00
05:58:00+00
```

下列範例只會選取小於 `3:00:00 UTC` 的 TIMETZ 值。將值轉換為 UTC 後進行比較。

```
select timetz_val from timetz_test where timetz_val < '3:00:00 UTC';
                  
   timetz_val
---------------
 00:00:00.5550+00
```

下列範例會比較兩個 TIMETZ 常值。比較時會忽略時區。

```
select time '18:25:33.123456 PST' < time '19:25:33.123456 EST';
                  
 ?column?
----------
 t
```