sql总结

子查询:

表达式子查询 

Select au_lname, au_fname from authors where city=  (select city from publishers where pub_name="abcde")

限定谓词子查询 
 Select pub_name from publishers from publishers  Where pub_id in  (select pub_id from titles where type='abcde')

相关查询  相关查询即嵌套查询依赖于外部父查询的值,嵌套查询要重复执行若干次。 
Select distinct t1.type from titles t1  Where t1.type in ( select t2.type from titles t2    where t1.pub_id!=t2.pub_id) 

集函数、分组与排序 
A、对查询结果进行聚集处理  聚集函数:
 Sum([all|distinct] expression),avg([all|distinct] exoression) ,
 Count([all|distinct]expression),
 count(*),
 max(expression),
 min(expression)
 Select count(*) from titles
B、用Group by 和 having 子句对查询结果分组  Select type ,avg(advance), sum(total_sales) from titles group by type  Select type from titles  group by type having count(*) >1  Having 类似于where , 但where 不能用聚集函数。 
C、用Order by 对查询结果进行排序  Select type ,avg(price) from titles group by type order by avg(price) 
D、Compute 子句  完成基于每一组中的值的聚集运算,聚集值作为一个新行出现在查询结果中。
 Select type ,price advance from titles order by type compute sum(price), sum(advance) by type

去重:

distinct

Select distinct tel from code_1th

group by ...having

Select type from titles  group by type having count(*) >1

like的用法:

通配符‘%’及‘-’,分别代表多个字符和单个字符

例: 查询以字母A 开头的:  select  *  from  table1 where name like 'A%'

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值