zoukankan      html  css  js  c++  java
  • mysql必知必会(四、检索数据,五、排序检索数据,六、过滤数据,七、数据过滤)

    四、select语句

    1、检索单个列

    select prod_name from products;

    2、检索多个列

    select prod_name, prod_price from products;

    3、检索所有列

    select * from products;

    4、检索不同的行

    select distinct vend_id from products;(vend_id只返回不同的值)

    5、限制结果

    select prod_name from products limit 开始位置,检索行数;

    6、使用完全限定的表名

    select products.prod_name from products;

    select products.prod_name from crashcourse.products;

    五、排序检索数据

    1、根据prod_name排序

    select prod_name from products order by prod_name;

    2、按多个列排序

    select prod_id, prod_price, prod_name from products order by prod_price, prod_name;

    3、指定排序方向

    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;

    六、过滤数据

    1、使用where子句

    select prod_name, prod_price from products where prod_price=2.50;

    where支持

    =,<>,!=,<,<=,>,>=,between

    2、检查单个值

    select prod_name, prod_price from products where prod_name = 'fuses';

    3、范围检查

    select prod_name, prod_price from products where prod_price between 5 and 10;

    4、空值检查

    select  prod_name from products where prod_price is null;

    七、数据过滤

    1、and操作符

    select prod_id, prod_price, prod_name from products where vend_id = 1003 and prod_price <= 10;

    2、or操作符

    select prod_name, prod_price from product where vend_id = 1002 or vend_id = 1003;

    3、计算次序

    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

    4、in操作符

    select prod_name, prod_price from products where vend_id in (1002, 1003) order by prod_name;

    5、not操作符

    select prod_name, prod_price from products where vend_id not in (1002, 1003) order by prod_name;

  • 相关阅读:
    微信下载远程图片的公用方法
    微信接口调用
    微信
    post方法
    asp.net pagebase获取缓存的方法
    sql查询最大id
    Controller里写自己需要的Action,参数的名字必须和路由设置的参数名一致

    递归调用
    队列及其应用
  • 原文地址:https://www.cnblogs.com/lgh344902118/p/10591991.html
Copyright © 2011-2022 走看看