zoukankan      html  css  js  c++  java
  • mysql 查询条件

      1简单查询   select* from 表名

                           select name as“姓名”fromstu     (把name改为名字)

    2条件查询 where 后面跟条件  条件要写清楚

    3模糊查询  like  no like    %代表任意多个字符   _代表一个字符

    4排序查询  order by 字段 排序值 (desc降 asc升)

    5范围查询     between....and...

    6离散查询  in  notin

    7聚合查询   sun 求和   count数据条数   max最大值  min最小值 avg平均值

    8分页查询 limit 从第几条开始,取多少数据

                     表名limit(pagesize-1)*5,5     pagesize是页数   *5 是每页条数 ,5 取多少条

    9去重查询 distinct      select distinct  表段名 from 表名

    10分组查询 group by 字段  having 条件

    select count(*),cno,group_concat(degree),sum(degree) from score group by cno ;

    select cno,group_concat(degree),sum(degree) from score group by cno having count(*)>3

    #分组之后根据条件查询使用having 不使用where

    高级查询

    1. 连接查询,对列的扩展

       Select * from student as stu,score as sc

    where stu.sno = sc.sno and sc.sno = “103” ;

    2.联合查询,对行的扩展

        select Code,Name from Info

        union

        select Code,Name from Nation

    3.子查询

    (1)无关子查询

    外层查询 (里层查询)

    子查询的结果当做父查询的条件

    子查询:select Code from Nation where Name='汉族'

    父查询:select * from Info where Nation = ''

        select * from Info where Nation = (select Code from Nation where Name='汉族')

    (2)相关子查询

        查询汽车表中油耗低于该系列平均油耗的所有汽车信息

        父查询:select * from Car where Oil<(该系列平均油耗)

        子查询:select avg(Oil) from Car where Brand = '某个系列'

        select * from Car a where Oil<(select avg(Oil) from Car b where b.Brand = a.Brand )

  • 相关阅读:
    JSP环境探针-当前电脑所有系统参数
    SqlServer service broker 分布式系统(赵松桃)跳水 2005 数据库编程
    主机Window不能访问该虚拟机Linux Samba文件服务提供了一个文件夹
    hdu 4901 The Romantic Hero
    linux、hdfs、hive、hbase经常使用的命令
    Android 设计模式模式适配器
    PHP扩展memcache模
    算法——字符串匹配Rabin-Karp算法
    三个重要的散列演示
    CodeForces 10C. Digital Root
  • 原文地址:https://www.cnblogs.com/w-xibao/p/7759760.html
Copyright © 2011-2022 走看看