

 Amazon Redshift tidak akan lagi mendukung pembuatan Python UDFs baru mulai Patch 198. Python yang ada UDFs akan terus berfungsi hingga 30 Juni 2026. Untuk informasi lebih lanjut, lihat [posting blog](https://aws.amazon.com/blogs/big-data/amazon-redshift-python-user-defined-functions-will-reach-end-of-support-after-june-30-2026/). 

Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.

# Kondisi logis
<a name="r_logical_condition"></a>

Kondisi logis menggabungkan hasil dari dua kondisi untuk menghasilkan satu hasil. Semua kondisi logis adalah operator biner dengan tipe pengembalian Boolean. 

## Sintaksis
<a name="r_logical_condition-synopsis"></a>

```
expression
{ AND | OR }
expression
NOT expression
```

Kondisi logis menggunakan logika Boolean tiga nilai di mana nilai nol mewakili hubungan yang tidak diketahui. Tabel berikut menjelaskan hasil untuk kondisi logis, di mana `E1` dan `E2` mewakili ekspresi:

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/id_id/redshift/latest/dg/r_logical_condition.html)

Operator NOT dievaluasi sebelum AND, dan operator AND dievaluasi sebelum operator OR. Tanda kurung apa pun yang digunakan dapat mengesampingkan urutan evaluasi default ini. 

### Contoh
<a name="r_logical_condition-examples"></a>

Contoh berikut mengembalikan USERID dan USERNAME dari tabel USERS tempat pengguna menyukai Las Vegas dan olahraga: 

```
select userid, username from users
where likevegas = 1 and likesports = 1
order by userid;

userid | username
--------+----------
1 | JSG99FHE
67 | TWU10MZT
87 | DUF19VXU
92 | HYP36WEQ
109 | FPL38HZK
120 | DMJ24GUZ
123 | QZR22XGQ
130 | ZQC82ALK
133 | LBN45WCH
144 | UCX04JKN
165 | TEY68OEB
169 | AYQ83HGO
184 | TVX65AZX
...
(2128 rows)
```

Contoh berikutnya mengembalikan USERID dan USERNAME dari tabel USERS di mana pengguna menyukai Las Vegas, atau olahraga, atau keduanya. Kueri ini mengembalikan semua output dari contoh sebelumnya ditambah pengguna yang hanya menyukai Las Vegas atau olahraga. 

```
select userid, username from users
where likevegas = 1 or likesports = 1
order by userid;

userid | username
--------+----------
1 | JSG99FHE
2 | PGL08LJI
3 | IFT66TXU
5 | AEB55QTM
6 | NDQ15VBM
9 | MSD36KVR
10 | WKW41AIW
13 | QTF33MCG
15 | OWU78MTR
16 | ZMG93CDD
22 | RHT62AGI
27 | KOY02CVE
29 | HUH27PKK
...
(18968 rows)
```

Kueri berikut menggunakan tanda kurung di sekitar `OR` kondisi untuk menemukan tempat di New York atau California tempat Macbeth dilakukan: 

```
select distinct venuename, venuecity
from venue join event on venue.venueid=event.venueid
where (venuestate = 'NY' or venuestate = 'CA') and eventname='Macbeth'
order by 2,1;

venuename                |   venuecity
----------------------------------------+---------------
Geffen Playhouse                       | Los Angeles
Greek Theatre                          | Los Angeles
Royce Hall                             | Los Angeles
American Airlines Theatre              | New York City
August Wilson Theatre                  | New York City
Belasco Theatre                        | New York City
Bernard B. Jacobs Theatre              | New York City
...
```

Menghapus tanda kurung dalam contoh ini mengubah logika dan hasil kueri. 

Contoh berikut menggunakan `NOT` operator: 

```
select * from category
where not catid=1
order by 1;

catid | catgroup |  catname  |                  catdesc
-------+----------+-----------+--------------------------------------------
2 | Sports   | NHL       | National Hockey League
3 | Sports   | NFL       | National Football League
4 | Sports   | NBA       | National Basketball Association
5 | Sports   | MLS       | Major League Soccer
...
```

Contoh berikut menggunakan `NOT` kondisi yang diikuti oleh suatu `AND` kondisi: 

```
select * from category
where (not catid=1) and catgroup='Sports'
order by catid;

catid | catgroup | catname |             catdesc
-------+----------+---------+---------------------------------
2 | Sports   | NHL     | National Hockey League
3 | Sports   | NFL     | National Football League
4 | Sports   | NBA     | National Basketball Association
5 | Sports   | MLS     | Major League Soccer
(4 rows)
```