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

  • 相关阅读:
    Scrapy 概览笔记
    Python 依赖版本控制 (requirements.txt 文件生成和使用)
    Python 虚拟空间的使用
    macOS 所有版本 JDK 安装指南 (with Homebrew)
    鉴权那些事
    Java 位运算符和 int 类型的实现
    ASP.NET Core 入门教程 5、ASP.NET Core MVC 视图传值入门
    如何做好一次知识或技术分享
    ASP.NET Core 入门教程 4、ASP.NET Core MVC控制器入门
    ASP.NET Core 入门教程 3、ASP.NET Core MVC路由入门
  • 原文地址:https://www.cnblogs.com/zhanghaozhe8462/p/5274507.html
Copyright © 2011-2022 走看看