2.mysql-select

基本语句结构:

  • select[字段表达式][from子句][group by 子句][having 子句][order by 子句][limit 子句]
  1. 字段表达式:
  • select 1+1
  • select now()
  • select unix_timestamp()
  • select 字段*10 from 表名

    2. as起别名:select 1+1 as a

    from子句:

  1. from + 列表名
  2. from + 列表名1,列表名2(结果为笛卡尔积)
  3. select now() from dual (dual为虚拟表)

    where 子句

  1. like模糊查询%和_
  2. not like
  3.  between ... and ...
  4. in 包含
  5. not in 不包含
  6. is null 空值判断 isnull()
  7. is not null 

    grounp by 子句

合计函数

  1. count()查询记录不为null的数
  2. sum()统计字段和
  3. avg()统计字段平均值
  4. max()
  5. min()
  6. group_concat()连接组内字段

    分组排序

  1. desc 降序
  2. asc 升序

    多字段分组

  1. with rollup可以回滚查看

    having子句

  1. where是从数据源检索
  2. having是得到结果后检索

    order by排序子句

  1. order by 字段名 [asc|desc], [字段名 [asc|desc],]

    limit子句

  1. limit start ,size

子查询,sub-query

  • select * 
    from student 
    where height=
    (select max(height) from student2)

子查询分类:

  • 根据子查询出现位置分类
  1. where 型子查询
  2. from型
  • 根据返回的数据格式
  1. 标量子查询 一个数据
  2. 列子查询 一列
  3. 行子查询 一行
  4. 表子查询 一个二维表

    exists(子查询)

    join查询 : form 表1 join 表2 on 连接条件

    内连接: inner join 外连接:左外连接 右外连接:left join right join

    交叉连接:cross join

    自然连接: natural join 

转载于:https://my.oschina.net/fseqy/blog/967441

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值