mysql必知必会(4、检索数据,5、排序检索数据,6、过滤数据,7、数据过滤)

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;

相关文章
相关标签/搜索