选择语句
use sql_store;
select *
from customers;
select
last_name,
first_name,
points,
points + 10,
(points + 10) * 100 as 'discount factor'
from customers;
select distinct state
from customers;
select name,unit_price,unit_price * 1.1 as new_price
from products;
where语句及相关
select *
from customers
where points > 3000 and state <> 'TX' or points = 3000 and state = 'TX';
select *
from ordes
where order_date >= '2019-01-01';
select *
from ordes
where not state = 'IL';
select *
from order_items
where order_id = 6 and unit_price * quantity > 30;
select *
from customers
where state not in ('VA','TX');
select *
from customers
where birth_date between '1990-01-02' and '2000-01-03';
select *
from customers
where last_name like '%b%' and
address not like '%trail%';
select *
from customers
where last_name like '%field%' and
last_name regexp 'field' or
last_name regexp '^field|mac|rose' or
last_name regexp '[a-h]e';
select *
from customers
where phone is null;
select *
from customers
order by state desc,first_name;
select birth_date, first_name, last_name, 10 as points
from customers
order by 1,2;
SELECT *,quantity * unit_price AS total_price
FROM order_items
WHERE order_id = 2
ORDER BY total_price DESC;
select *
from customers
limit 3
offset 3
创建数据库
CREATE DATABASE 数据库名
DELETE 语句
DELETE FROM table_name [WHERE Clause]
- 如果没有指定 WHERE 子句,MySQL 表中的所有记录将被删除。
- 你可以在 WHERE 子句中指定任何条件
- 您可以在单个表中一次性删除记录。