zoukankan      html  css  js  c++  java
  • 数据库-T-SQL 语句-简单查询

    1.普通查询

    select * from Info #查询所有内容

    select Code,Name from Info #查询指定列

    2.条件查询

    select * from Info where Code ='p001'  #筛选行,单条件

    select * from Info where Nation = 'n001' and Sex = true  #多条件查询 并的关系

    select * from Info where Sex = false or Nation = 'n002'  #多条件查询 或的关系

    3.模糊查询

    select * from ChinaStates where AreaName like '中%'  #  %代表任意多个字符

    select * from ChinaStates where AreaName like '%城%'

    select * from ChinaStates where AreaName like '_ 城%' # _表示任意一个字符,“城”在第二个位置出现

    4.排序查询

    默认以主键值升序排列

    asc 升序

    select * from Car order by Code desc    #order by 列名 desc    根据Code列降序排列

    select * from Car order by Brand    #根据Brand列默认升序排列

    select * from Car order by Brand,Powers  #根据两个条件排序 以第一个为主 第一个一样,再按第二个排序

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

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

    select max(Price) from Car  #查询某一列的最大值

    select min(Price) from Car  #查询某一列的最小值

    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的  用having 筛选

    7.分页查询

    (页数-1)*每页条数

    select * from Car limit 0,5  #跳过几条数据取几条

  • 相关阅读:
    定位
    supervisor进程管理工具
    简单git使用命令
    django + Vue项目上线部署
    Vue配置浏览器头部图标和title
    vue打包项目后 谷歌浏览器可以打开,其他浏览器不行
    js反向解析爬取企**网站
    python常用排序算法
    python脚本demo
    request模块封装
  • 原文地址:https://www.cnblogs.com/yifangtongxing/p/5326131.html
Copyright © 2011-2022 走看看