SELECT语句

常见的SELECT语法

# 使用XX表语法
USE sql_store;
SHOW tables;

# 选择所有列
SELECT *
FROM customers;

# 选择部分列, 也可以做运算
SELECT last_name, first_name, points, points % 10
FROM customers;

SELECT last_name, first_name, points, points * 10 + 100
FROM customers;
# AS 可以命名别名
SELECT 
	last_name, 
	first_name, 
        points, 
	(points + 10) * 100 AS 'discount factor'
FROM customers;
# DISTINCT 去重
SELECT state 
FROM customers;
SELECT DISTINCT state 
FROM customers;
-- WHERE customer_id = 1
-- ORDER BY first_name;
# 练习题
-- Return all the products
-- name
-- unit price 
-- new price (unit price * 1.1)
SELECT 
      name,
    unit_price,
    unit_price * 1.1 AS new_price
FROM products;
上一篇:RL | | Sliver Course


下一篇:ADO 查询