zoukankan      html  css  js  c++  java
  • 普通查询

    1.普通查询
    select * from Info --查询所有内容--

    select Code,Name from Info --查询某几列--

    2.条件查询

    select * from Info where Nation ='n001' --条件查询--

    select *from Info where Nation ='n001' and Sex = true --满足两个条件的,用and,条件之间是并的关系--

    select * from Info where Sex =false or Nation ='n002' --条件之间是或的关系,用or--

    select * from Car where Price>50 and Price<60 --范围查询--

    select * from Car where Price<30 or Price >60 --范围查询--

    3.模糊查询

    select * from ChinaStates where AreaName like '中%' --查询以‘中’开头的,关键字like,%代表任意多个字符

    select *from ChinaStates where AreaName like '%城%' --查询包含‘城’这个字的信息--

    select *from ChinaStates where AreaName like '_城%' --‘城’在第二个位置出现,下划线代表任意一个字符--

    4.排序查询

    select *from car order by Code desc --desc是降序的意思,asc是升序--

    select *from car order by Brand,Powers --先按照Brand排序,再按照Powers排序--

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

    select count(*) from Car --查询总条数--

    select max(price) from Car --查询Price这一列的最大值,最小值换成min--

    select avg(Price) from Car --查询平均值--

    select sum(Price) from Car --查询总和--

    6.分组查询

    select Brand,count(*)from Car group by Brand --根据系列分组查看每组的数据条数,也可以求和,
    求最大,最小,平均数--
    以Brand来分组,看里面有多少条数据

    select * from Car group by Brand having count(*)>2
    以Brand分组,看里面数据大于2条的

    7.分页查询

    select * from Car limit 0,5 --跳过几条数据,取几条数据--
    跳过0条数据,来取5条,取得是0-5条

    select * from Car limit 5,5
    跳过5条数据,来取5条,取得是6-10条


    8.去重查询
    select distinct Brand from Car

  • 相关阅读:
    [django]自定义标签和过滤器
    [js]js中6种错误处理机制
    [js] Array.slice和类数组转数组
    [js]this和call.call
    [py]python的time和datetime模块获取星期几
    CentOS 普通用户提升root权限
    CentOS ACL
    CentOS 文件隐藏属性
    CentOS 文件特殊权限SUID,SGID,SBIT
    CentOS 用户管理useradd、usermod等
  • 原文地址:https://www.cnblogs.com/zhanghaozhe8462/p/5274507.html
Copyright © 2011-2022 走看看