sql like不包括
SQL LIKE is used with WHERE clause to search for a pattern for a column. Wildcards are the one which is used for specifying the pattern.
SQL LIKE与WHERE子句一起使用以搜索列的模式。 通配符是用于指定模式的通配符。
There are two wildcards that are used with the LIKE operator.
LIKE运算符使用两个通配符。
- %: Percentage is used for representation of single, multiple or no occurrence. % :百分比用于表示一次,多次或不出现。
- _: The underscore is used for representation of a single character. _ :下划线用于表示单个字符。
To use SQL LIKE operator, we must be very sure of the usage of the wildcard position as that will define the search pattern.
要使用SQL LIKE运算符,我们必须非常确定通配符位置的用法,因为这将定义搜索模式。
SQL类语法 (SQL Like Syntax)
SQL Like operator can be used with any query with where clause. So we can use it with Select, Delete, Update etc.
SQL Like运算符可与任何带有where子句的查询一起使用。 因此,我们可以将其与Select , Delete , Update等一起使用。
SELECT column FROM table_name WHERE column LIKE pattern;
UPDATE table_name SET column=value WHERE column LIKE pattern;
DELETE FROM table_name WHERE column LIKE pattern;
In the sql like syntax mentioned above the “pattern” is the one that is defined by the usage of wildcards.
在上述类似sql的语法中,“模式”是使用通配符定义的模式。
SQL样例 (SQL Like Example)
Let’s try to understand the usage of SQL LIKE statement along with wildcards by some examples. Consider the following Customer table for the example.
让我们尝试通过一些示例来了解SQL LIKE语句以及通配符的用法。 请考虑以下客户表作为示例。
CustomerId | CustomerName |
---|---|
1 | Amit |
2 | John |
3 | Annie |
顾客ID | 顾客姓名 |
---|---|
1个 | 阿米特 |
2 | 约翰 |
3 | 安妮 |
- Find customer name with name starting with ‘A’.
SELECT CustomerName FROM Customer WHERE CustomerName LIKE 'A%';
Output:
Amit
Annie输出 :
阿米特
安妮 - Find customer name with name ending with ‘e’.
SELECT CustomerName FROM Customer WHERE CustomerName LIKE '%e'
Output: Annie
输出 :安妮
- Find customer name with name starting with ‘A’ and ending with ‘t’.
SELECT CustomerName FROM Customer WHERE CustomerName LIKE 'A%t'
Output: Amit
输出 :Amit
- Find customer name with name containing ‘n’ at any position.
SELECT CustomerName FROM Customer WHERE CustomerName LIKE '%n%'
Output:
Annie
John输出:
安妮
约翰 - Find customer name with name containing ‘n’ at second position.
SELECT CustomerName FROM Customer WHERE CustomerName LIKE '_n%'
Output: Annie
输出 :安妮
- Find customer name with name containing ‘i’ at third position and ending with ‘t’.
SELECT CustomerName FROM Customer WHERE CustomerName LIKE '__i%t'
Output: Amit
输出 :Amit
SQL不喜欢 (SQL Not Like)
Sometimes we want to get records that doesn’t match the like pattern. In that case we can use sql not like operator. SQL not like statement syntax will be like below.
有时我们想要获取与like模式不匹配的记录。 在这种情况下,我们可以使用sql而不是运算符。 SQL不喜欢的语句语法将如下所示。
SELECT column FROM table_name WHERE column NOT LIKE pattern;
UPDATE table_name SET column=value WHERE column NOT LIKE pattern;
DELETE FROM table_name WHERE column NOT LIKE pattern;
As an example, let’s say we want the list of customer names that don’t start with ‘A’. Below query will give us the required result set.
例如,假设我们想要一个以“ A”开头的客户名称列表。 下面的查询将为我们提供所需的结果集。
SELECT CustomerName FROM Customer WHERE CustomerName NOT LIKE 'A%';
Output: John
输出 :约翰
SQL多重赞 (SQL Multiple Like)
We can have multiple like statements in SQL query. For example, if we want a list of customer names starting from ‘Jo’ and ‘Am’ then we will have to use multiple like statements like below.
SQL查询中可以有多个like语句。 例如,如果我们想要一个以“ Jo”和“ Am”开头的客户名称列表,那么我们将不得不使用多个类似的语句,如下所示。
SELECT CustomerName FROM Customer WHERE CustomerName LIKE 'Am%' OR CustomerName LIKE 'Jo%';
That’s all for SQL like operator and SQL not like operator examples.
对于像SQL一样的运算符,对于SQL而言,不像运算符示例那样。
sql like不包括