9.LIKE, NOT LIKE匹配

字符串模糊匹配可以使用WHERE子句中的Like运算符来完成。

关键字右边的参数是表达式必须匹配的模式。在这些模式中,%是匹配零个或多个字符的通配符,并且_(下划线)是完全匹配一个字符的通配符。

在下边的例子中,我们寻找那些拥有YaHoo电子邮件地址的人。

LIKE Query

SELECT fname, email
    FROM tutorial 
        WHERE email LIKE '%@yahoo.com'

结果

{
  "results": [
    {
      "email": "harry@yahoo.com",
      "fname": "Harry"
    }
  ]
}

NOT LIKE Query:

SELECT fname, email
    FROM tutorial 
        WHERE email NOT LIKE '%@yahoo.com'

结果:

{
  "results": [
    {
      "email": "dave@gmail.com",
      "fname": "Dave"
    },
    {
      "email": "earl@gmail.com",
      "fname": "Earl"
    },
    {
      "email": "fred@gmail.com",
      "fname": "Fred"
    },
    {
      "email": "ian@gmail.com",
      "fname": "Ian"
    },
    {
      "email": "jane@gmail.com",
      "fname": "Jane"
    }
  ]
}

Last updated

Was this helpful?