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;

  • 相关阅读:
    用 Python 脚本实现对 Linux 服务器的监控
    linux系统常用命令
    一小时学会用Python Socket 开发可并发的FTP服务器!!
    Python获取程序运行目录和脚本目录
    哪些情况会导致OOM
    如何查看端口状态
    wait(),sleep(),notify(),join()
    cookie和session的区别与会话跟踪技术
    TCP的可靠性
    OSI和TCP/IP的对比+IP地址分类
  • 原文地址:https://www.cnblogs.com/lgh344902118/p/10591991.html
Copyright © 2011-2022 走看看