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

    1 简单查询(查所有数据)

    select * from表名;   注:*代表所有列

    select * from info          所有行所有列

    2 查询指定列

    select code, name from info

    3 修改结果集的列名

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

    4 条件查询

    select * from info where条件 code='p003'

    5 多条件查询

    查询info表中code为p003或者nation为n001的所有数据

    select * from info where code='p003' or nation='n001'

    查询info表中code为p004并且nation为n001的数据

    select * rom info where code='p004' and nation='n001'

    6 范围查询

    select * from car where price>=40 and price<=60

    select * from car where between 40 and 60

    7 离散查询

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

    select * from car where price=10 or price=20 or price=30 or price=40 or price=50 or price=60 比较繁琐

    select * from car where price in(10,20,30,40,50,60) 相对简便

    select * from car where price not in(10,20,30,40,50,60) 不在范围内的

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

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

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

    查询汽车表中第二个字符为'马'的汽车

    select * from car where name like '_马%'    "_"  任意一个字符

    9 排序查询

    用价格排序

    select * from car order根据 by price asc                       asc代表升序(默认的可以省略)

    select * from car order根据 by oil desc                         desc代表降序(不能省略)

    先按照brand升序排,在按照price降序排     两列排

    select * from car order  by brand,price desc      先根据主要的排

    10 去重查询   (出现重复数据,进行去除)

    select distinct brand from car        distinct  去重  加在列的前面

    11 分页查询   (针对于分页多显示不全)

    一页显示10条数据,当前是第二页

    select * from chinastates limit 10, 10               limit用来做分页        跳过多少条   ,   取多少条

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

    limit (n-1)*m, m

    12 聚合函数   (统计用的,也可以称为统计函数)

    select count(*)from chinastates              count是一个方法查询数据总条数  加*的时候代表所有列进行统计

    select count(areacode)from chinastates     换成主键列只看第一列的值

    select sum(price) from car     sum  求和

    select avg(price) from car      avg   求平均

    select max(price) from car     max  求最大值

    select min(price) from car      min   求最小值

    13 分组查询   (查询表数据的时候,根据数据不同的时候进行分组)      难点!

    查询汽车表中每个系列下有多少汽车

    select brand,count(*) from car group by brand

    查询汽车表中所卖的汽车数量大于3的系列(达到指标的)

    select brand from car group by brand having  count(*)>3              如果前面出现了group 后边必跟having

  • 相关阅读:
    MR中简单实现自定义的输入输出格式
    简单实现CombineFileInputFormat
    提高mapreduce性能的七点建议
    MR中使用sequnceFIle输入文件
    Hive中使用LZO
    JVM启动参数详解 (转)
    ubuntu12.04中shell脚本无法使用source的原因及解决方法
    hadoop 错误
    poj 3211 Washing Clothes
    hdu 3535 AreYouBusy
  • 原文地址:https://www.cnblogs.com/zqseven/p/6124731.html
Copyright © 2011-2022 走看看