MySQL学习笔记

Get data

SELECT prod_name FROM products;
SELECT prod_name, prod_price FROM products;
SELECT * FROM products;
SELECT DISTINCT vend_id FROM products;
SELECT prod_name FROM products LIMIT 5;
SELECT prod_name FROM products LIMIT 5, 5;
SELECT products.prod_name FROM products;
SELECT prod_name FROM products ORDER BY prod_name;
SELECT prod_id, prod_price, prod_name
FROM products
ORDER BY prod_price, prod_name;
SELECT prod_name, prod_price FROM products
ORDER BY prod_price DESC;
# If you want to sort descending on mulitple columns, 
# be sure each column has its own DESC keyword.
Filting Data
SELECT prod_name, prod_price
FROM products
WHERE prod_price = 2.50;

SELECT prod_name, vend_id
FROM products
WHERE vend_id <> 1003;

SELECT prod_name, prod_price
FROM products
WHERE prod_price BETWEEN 5 AND 10;

SELECT prod_name
FROM products
WHERE prod_price IS NULL;
Advanced Data Filtering
SELECT prod_id, prod_price, prod_name
FROM products
WHERE vend_id = 1003 AND prod_price < 10;

SELECT prod_name, prod_price
FROM products
WHERE vend_id = 1002 OR vend_id = 1003;

SELECT prod_name, prod_price
FROM products
WHERE (vend_id = 1002 OR vend_id = 1003) AND prod_price >= 10;
# AND ranks higher in the order of evaluation than OR.

SELECT prod_name, prod_price
FROM products
WHERE vend_id IN (1002, 1003)
ORDER BY prod_name;

SELECT prod_name, prod_price
FROM products
WHERE vend_id NOT IN (1002, 1003)
ORDER BY prod_name;
Wildcard Filtering

Try to not use wildcards, never overuse them.

SELECT prod_id, prod_name
FROM products
WHERE prod_name LIKE 'jet%';

SELECT prod_id, prdo_name
FROM products
WHERE prod_name LIKE '%anvil%'

SELECT prod_id, prod_name
FROM products
WHERE prod_name LIKE '_ ton anvail';
# - matches just one character
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值