AI 助力的 SQL 查询进阶
Jasmin Ludolf
Senior Data Science Content Developer


$$
*:选择所有$$
两个模式匹配通配符:
%_
提示: 显示包含"love"的电影标题
SELECT title
FROM films
WHERE title LIKE '%love%';
|title |
|------------------------|
|Dr. Strangelove or: H...|
|Beloved |
|Cloverfield |
|The Oogieloves in the...|
...
$$
%:
%love%:提示: 显示包含"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"提示: 显示以"and"结尾(任意大小写)的电影标题
SELECT title
FROM films
WHERE LOWER(title) LIKE '%and';
|title |
|------------------------|
|Alexander's Ragtime Band|
|Wonderland |
|Finding Neverland |
...
提示: 显示以"and"开头(任意大小写)的电影标题
SELECT title
FROM films
WHERE LOWER(title) LIKE 'and%';
|title |
|------------------|
|And Then Came Love|
|Anderson's Cross |
|And So It Goes |
提示: 显示以 E 开头、5 个字母的电影标题
SELECT title
FROM films
WHERE title LIKE 'E____';
|title|
|-----|
|Evita|
|Earth|
提示: 显示标题不以"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 查询进阶