使用 AI 進行 SQL 查詢進階
Jasmin Ludolf
Senior Data Science Content Developer


$$
*: 選取全部$$
兩種樣式比對萬用字元:
%_
Prompt: 顯示包含 'love' 的片名
SELECT title
FROM films
WHERE title LIKE '%love%';
|title |
|------------------------|
|Dr. Strangelove or: H...|
|Beloved |
|Cloverfield |
|The Oogieloves in the...|
...
$$
%:
%love%:Prompt: 顯示不分大小寫包含 'love' 的片名
SELECT title
FROM films
WHERE title ILIKE '%love%';
|title |
|---------------------|
|Intolerance: Love'...|
|Love Me Tender |
|From Russia with Love|
...
SELECT title
FROM films
WHERE LOWER(title) LIKE '%love%';
$$
LOWER(title):"love actually"SELECT title
FROM films
WHERE UPPER(title) LIKE '%LOVE%';
$$
UPPER(title):"LOVE ACTUALLY"Prompt: 顯示以 'and' 結尾的片名(不分大小寫)
SELECT title
FROM films
WHERE LOWER(title) LIKE '%and';
|title |
|------------------------|
|Alexander's Ragtime Band|
|Wonderland |
|Finding Neverland |
...
Prompt: 顯示以 'and' 開頭的片名(不分大小寫)
SELECT title
FROM films
WHERE LOWER(title) LIKE 'and%';
|title |
|------------------|
|And Then Came Love|
|Anderson's Cross |
|And So It Goes |
Prompt: 顯示以 E 開頭、長度為 5 的片名
SELECT title
FROM films
WHERE title LIKE 'E____';
|title|
|-----|
|Evita|
|Earth|
Prompt: 顯示片名不是以 'The' 開頭的電影
SELECT title
FROM films
WHERE title NOT LIKE 'The%';
|title |
|--------------------|
|Intolerance: Love...|
|Over the Hill to ...|
|Metropolis |
...


$$
$$
$$
*:選取所有欄位_:單一字元比對%:位置比對
LIKE:樣式比對NOT LIKE:排除樣式ILIKE:不分大小寫UPPER()/LOWER():統一大小寫使用 AI 進行 SQL 查詢進階