mysql+select+排版_mysql select

select a, b, t1.c, a*b as d

from t1, db.t2

where a between 3 and 7 or c not in (5,100,124)

group by ...

having ...

order by d desc, e select的列里没有e

limit 5; 等价于limit 0,5 和 limit 5 offset 0

select distinct a,b from table; 去重,放在所有列之前,作用于所有列,

即a、b两列都相同才视为相同

select concat( rtrim(a), ‘ (‘, b, ‘)‘ ) as c 连接、去空格、别名

select a*b + - * /

子查询

子查询作为where条件,多与in配合使用,也可以和=或<>配合使用

where a in (select a from t where b=3) as t2;

子查询作为计算字段

select cname, (select count(*)

from orders

where orders.cid=customers.cid) as orders

from customers;

子查询作为from字段

select a from (select ...) temp //不加别名报错

union

列必须相同,但次序可以不同

列数据类型必须兼容,可以隐式转换

order by只能在最后一个select后面出现一次,对全部数据排序

select a from t where a>2

union

select a from t where a<6

若存在1行a=3,只会被返回一次,union会自动去重

union all 返回所有行

select省略from,可用来处理表达式:select 3*2、select now() 等

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值