4、select語句排序
一、檢索單個列it
select prod_name from products;select
二、檢索多個列im
select prod_name, prod_price from products;數據
三、檢索全部列di
select * from products;co
四、檢索不一樣的行
select distinct vend_id from products;(vend_id只返回不一樣的值)
五、限制結果
select prod_name from products limit 開始位置,檢索行數;
六、使用徹底限定的表名
select products.prod_name from products;
select products.prod_name from crashcourse.products;
5、排序檢索數據
一、根據prod_name排序
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_id, prod_price, prod_name from products order by prod_price desc;(desc降序,asc升序)
select prod_id, prod_price, prod_name from products order by price_price desc, prod_name;
select prod_price from products order by prod_price desc limit 1;
6、過濾數據
一、使用where子句
select prod_name, prod_price from products where prod_price=2.50;
where支持
=,<>,!=,<,<=,>,>=,between
二、檢查單個值
select prod_name, prod_price from products where prod_name = 'fuses';
三、範圍檢查
select prod_name, prod_price from products where prod_price between 5 and 10;
四、空值檢查
select prod_name from products where prod_price is null;
7、數據過濾
一、and操做符
select prod_id, prod_price, prod_name from products where vend_id = 1003 and prod_price <= 10;
二、or操做符
select prod_name, prod_price from product 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在or)
select prod_name, prod_price from products where (vend_id = 1002 or vend_id = 1003 )and prod_price >= 10
四、in操做符
select prod_name, prod_price from products where vend_id in (1002, 1003) order by prod_name;
五、not操做符
select prod_name, prod_price from products where vend_id not in (1002, 1003) order by prod_name;