收集的一些SQL(更新中)

sql语句的条件查询有:in,like,beteen...and,is null,is not null等,在条件中还可以包含select子查询。
sql比较查询运算符有:= ,>,<>,<,!=,<>,>=,<=,!>,!<;一般有数字比效,字符串比较,日期比效。
sql逻辑运算符共有3种:and,or,not
sql谓词in查询:例
select * from 定单 where zhigong (not) in('a','b','c','d')
sql模糊like查询:
例1 select * from zhigong where xingming not like '王%'
例2 select * from zhigong where xingming not like '王_'
sql空值查询: 例 select * from zhigong where xingbie is null
例2 select * from zhigong where xingbie is not null
sql限制范围查询:between...and 例 select * from zhigong where gongzi between 1300 and 1900
sql消除重复字段数据distinct查询 例 select distinct gongzi from zhigong
sql单表嵌套查询 select * from canghu where mianji>(select mianji from cangku where cangkuhao='wh')
sql多表嵌套查询
例1 select * from zhigong where cangkuhao in (select cangkuhao from cangku where chengshi='北京')
例2 select * from dingdan where zhigonghao in(select zhigonghao from zhigong where cangkuhao in ( select cangkuhao from cangku where chengshi='beijing'))
例3 select * from dingdan where zhigonghao in(select zhigonghao from zhigong where gongzi>1200 and cangkuhao in(select cangkuhao from cangku where chengshi='北京'))and 订购日期 between '2003-09-03'and '2006-01-01'
例4 select * from zhigong where zhigonghao in(select zhigonghao from dinggoudan)
例5 select * from zhigong where cangkuhao in(select cangkuhao from cangku where chengshi is not null) and gongzi between 1300 and 2100 and zhigonghao in (select zhigonghao from dinggoudan where jine not between 8000 and 12000)
例6 select * from zhigong where gongzi between(select gongzi from zhigong where zhigonghao='ad') and (select gongzi from zhigong where zhigonghao='df') and cangkuhao in (select cangkuhao from cangku where chengshi='beijin')
分组查询 分组查询关键词是group by 分组之前的关键词要用where 分组这后要用having
例 select cangkuhao,max(gongzi) as zuodagongai,min(gongzi)as zuixiaogongzi sum(gongzi) as gongzizonghe,avg(gongzi) as pinjungongzi,count(*)as zhigongrenshu from zhigong where gongzi>(select gongzi from zhigong where zhigonghao='aa') group by cangkuhao having avg(gongzi)>1760
*/

快速清空表内容:
例 truncate table xxxx \ truncate table user.xxxx 注:user为数据库的用户,就是清空user用户的xxxx表内容。

复制一个表中的数据到另外一个表:
例 create table yyy as select * from uuu。即把uuu表中的数据复制到yyy中。

同样可以复制到同服务器上的oracle中的其他用户里(用user为例):
create table user.yyy as select * from uuu
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值