zoukankan      html  css  js  c++  java
  • MySQL简单查询

    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 Nation = 'n001' and sex = '1'

    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.排序

    select * from Car order by Code desc #desc降序 asc升序

    select * from Car order by Brand

    select * from Car order by Brand,Powers #按照两个列排序

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

    select count(*) from Car #查询总条数 * 代表所有列

    select count(Code) from Car #查询某一列

    select max(Price) from Car #查询 price列里的最大值

    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)分组(group)查看每组的数据条数

    select Code,Brand,count(*) from Car group by Brand #根据Brand分组查看Code,Brand的数据条

    select * from Car group by Brand having count(*) >2 #查询分组之后数据条数大于2的,group后面不能加 where

    7.分页查询
    select * from Car limit 0,5 #查询跳过0条 取5条

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

  • 相关阅读:
    HDU 4864 Task(贪心值得学习)
    使程序在Linux下后台运行
    KMP算法
    优先队列的使用
    POJ 2761 Feed the dogs(树状数组求区间第K大)
    HDU 3584 Cube (三维树状数组)
    HDU 1892 See you~ (二维树状数组)
    POJ 1195 Mobile phones(二维树状数组)
    HDU 1166 敌兵布阵 (树状数组和线段树解法)
    POj 1703 Find them, Catch them(关系并查集)
  • 原文地址:https://www.cnblogs.com/ds-3579/p/5470949.html
Copyright © 2011-2022 走看看