sql like不包括_SQL Like – SQL不喜欢

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运算符使用两个通配符。

  1. %: Percentage is used for representation of single, multiple or no occurrence.

    :百分比用于表示一次,多次或不出现。
  2. _: 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子句的查询一起使用。 因此,我们可以将其与SelectDeleteUpdate等一起使用。

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语句以及通配符的用法。 请考虑以下客户表作为示例。

CustomerIdCustomerName
1Amit
2John
3Annie
顾客ID 顾客姓名
1个 阿米特
2 约翰
3 安妮
  1. Find customer name with name starting with ‘A’.
    SELECT CustomerName FROM Customer WHERE CustomerName LIKE 'A%';

    Output:
    Amit
    Annie

    输出
    阿米特
    安妮

  2. Find customer name with name ending with ‘e’.
    SELECT CustomerName FROM Customer WHERE CustomerName LIKE '%e'

    Output: Annie

    输出 :安妮

  3. Find customer name with name starting with ‘A’ and ending with ‘t’.
    SELECT CustomerName FROM Customer WHERE CustomerName LIKE 'A%t'

    Output: Amit

    输出 :Amit

  4. Find customer name with name containing ‘n’ at any position.
    SELECT CustomerName FROM Customer WHERE CustomerName LIKE '%n%'

    Output:
    Annie
    John

    输出:
    安妮
    约翰

  5. Find customer name with name containing ‘n’ at second position.
    SELECT CustomerName FROM Customer WHERE CustomerName LIKE '_n%'

    Output: Annie

    输出 :安妮

  6. 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而言,不像运算符示例那样。

翻译自: https://www.journaldev.com/18848/sql-like-sql-not-like

sql like不包括

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值