zoukankan      html  css  js  c++  java
  • 数据库查询

    1.范围查找

    select * from 表名 where price>40 and price<80

    select * from 表名 where price between 40 and 80

    2.离散查询

    select * from 表名 where price=30 or price=50

    select * from 表名 where price in(30,40,50)

    select * from 表名 where price not in(30,40,50)

    3.聚合函数(统计查询)

    select count (*) from 表名

    select count (code) from 表名#取所有的数据条数

    select sum(price) from car #求价格总和

    select avg(price) from car #求价格的平均值

    select max(price) from car #求最大值

    select min(price) from car #求最小值

    4.分页查询

    select * from car limit 0,10  #分页查询,跳过几条数据(0)取几条(10)

    规定一个每页显示的条数:m
    当前页数:n
    select * from car limit (n-1)*m,m

    5.去重查询

    select distinct 列名 from 表名#去重

    6.分组查询

    查询汽车表中,每个系列下汽车的数量

    select brand,count(*)求和 from car group by brand#分组

    分组之后只能查询该列或聚合函数

    取该系列价格平均值大于40的系列代号

    select brand from car group by brand having avg(price)>40

    取该系列油耗最大值大于8的系列代号
    select brand from car group by brand having max(oil)>8

  • 相关阅读:
    Redhat 7使用CentOS 7的Yum网络源
    指定YUM安装包的体系结构或版本
    CURL常用命令
    VIM技巧之去除代码行号并缩进代码
    VIM 中鼠标选择不选中行号
    linux服务器性能优化
    阻塞,非阻塞,同步,异步
    WEB三层架构与MVC
    mvc与三层结构
    Centos环境下Tomcat启动缓慢
  • 原文地址:https://www.cnblogs.com/yangmengchao/p/11006003.html
Copyright © 2011-2022 走看看