AND OR NOT
{
SELECT *
FROM customers
WHERE NOT (birth_date >'1990-01-01' OR points>1000 );
}
IN
{
SELECT *
FROM products
WHERE quantity_in_stock IN (49,38,72) -- quantity=49 OR 38 OR 72
}
BETWEEN
{
SELECT *
FROM customers
WHERE birth_date BETWEEN '1990-01-01' AND '2000-01-01'
}
LIKE
{
SELECT *
FROM customers
WHERE last_name LIKE '%b%' -- % represent any number of characters
---
SELECT *
FROM customers
WHERE last_name NOT LIKE 'b____y' -- _ represent single characters
---
SELECT *
FROM customers
WHERE address LIKE '%trail%' OR
address LIKE '%avenue%'
}
REGEXP(正则表达式)
{
SELECT *
FROM customers
WHERE last_name REGEXP 'field$|^mac|rose' -- ^ beginning $ end | logical OR
---
SELECT *
FROM customers
WHERE last_name REGEXP 'e[gim]' -- 等价于eg OR ei OR em
---
SELECT *
FROM customers
WHERE last_name REGEXP '[a-h]e' -- from a to h和e组合,等价于ae OR be OR ce …OR he
}
IS NULL
{
SELECT *
FROM customers
WHERE phone IS NOT NULL
}
ORDER BY
{
SELECT *
FROM customers
ORDER BY state DESC,first_name -- DESC 降序
---
SELECT first_name,last_name
FROM customers
ORDER BY birth_date
---
SELECT first_name,last_name,points
FROM customers
ORDER BY 1,2 -- 表示用相对列顺序排序,对应SELECT的顺序,这里等价于ORDER BY first_name,last_name
---
SELECT
*,
quantity*unit_price AS total_price
FROM order_items
WHERE order_id=2
ORDER BY total_price DESC
}
LIMIT
{
SELECT *
FROM customers
LIMIT 6,3 -- 其中6是偏移量,表示跳过前6条记录(行),从第7行开始(包括第7行)获取3条记录,这里每个记录即为 一行
---
SELECT *
FROM customers
ORDER BY points DESC
LIMIT 3 -- 等价于LIMIT 0,3 ,是直接取值到第3位
}