• CRUD查询


    简单查询:

    1.最简单的查询


    select*form 表名; *查所有的列
    select*form info


    2.查询指定列

    select code,name form info


    3.修改结果集的列名

    select code as'代号',name as '姓名' form info

    4.条件查询

    select * form info where code='p003'

    5.多条件查询

    查询info表中code为p003或者nation为001的所有数据
    select * form info where code = 'p003' or nation='n001'
    查询info表中code为p004并且nation为n001的数据
    select * from info where code='p004'and nation='n001'

    6.范围查询

    select * form car where price >=40 and price<=60
    select * form car where price between 40 and 60

    7.离散查询

    查询汽车价格在(10,20,30,40,50,60)中出现的汽车信息

    select * form car where price = 10 or price = 20 or price = 30 or price = 40 or
    price = 50 or price = 60

    select * form car where price in(10,20,30,40,50,60)
    select * form car where price not in(10,20,30,40,50,60)

    8.模糊查询(关键字查询)

    查询car表里面名称包含奥迪的

    select * form car where name like '%奥迪%' %任意n个字符

    查询car中第二个名称第二个字符为'马'的汽车

    select * form car wherename lkir'_马%' _任意一个字符

    9.排序查询

    select * form car order by priceasc asc asc升须(省略)
    select * form car order by oil desc desc降序

    首先照brand升序排,再按照price降序排

    select * form car order by brand,price desc


    10.去重查询

    select distinct brand form car

    11.分页面查询

    一页显示10条 当前是第三页

    select * form chinastates limit 20,10

    一页显示m条 当前是第n页

    limit (n-1)*m,n

    12.集合函数

    select count(areacode)form chinastates #查询数据总条数
    select sum (price)form car #求和
    select avg (price)form car #求平均值
    select max (price)form car #求最大值
    select min(price)form car #求最小值

    13、分组查询
    查询汽车表中每个系列下有多少个汽车
    select brand,count(*) form car groip by brand

    查询汽车表中麦的汽车数量大于3的系列
    select * form car group by brand having count(*)>3

  • 相关阅读:
    Trie树
    递归函数两种方式的区别
    揭开HTTPS的神秘面纱
    补码到底是个什么东西
    浮点数的运算精度丢失
    PHP的stdClass
    2019-10-24
    MySQL存储引擎
    代码整洁之道小结
    NFS4 挂载同主机多个目录
  • 原文地址:https://www.cnblogs.com/hao0/p/6124743.html
Copyright © 2020-2023  润新知