常用SQL

查询:
select ... from ... where ... group by ... having ...;

左连接右连接全连接
left join、  right join、 full join、 inner join 内连接、等值连接
若A有10条数据,B中有15条数据,AB中公共数据有5条
select * from A left join B on ...  结果为10条数据
select * from A right join B on ... 结果为15条数据
select * from A full join B on ... 结果为20条数据
select * from A inner join B on ... 结果为5条数据  

exists 与 in
exists用检查子检查的返回值为true或false。
例:select * from A where exists ( select null )  等价于 select * from A
select * from A where exists (select B.the_id from B where the_id=A.the_id)
select * from A where the_id in (select distinct(the_id) from B)
in只能判断一列,且exists的效率一般比in高,因为in不走索引


isnull(列名,替换字符串)
case when 列名=‘’ then '空' else '非空' end

union 与 union all
A中10条记录,B中15条记录,5条重复记录
select a,b,c from table_A
union
select a,b,c from tbale_B 
union默认删除重复记录,所以结果为20条记录

select a,b,c from table_A
union all 
select a,b,c from table_B
直接连接两个查询结果,共25条记录
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值