oracle中常见的查询操作

普通查询:
select * from t;


去除重复值:
select distinct f1,f2 from t;


between用法:
select * from t where f1 not/between 1and 2;


like用法:
select * from t where f1 not/like '_MDB%';


in用法:
select * from t where f1 not/in (n1,n2..);


显示前5行:
select * from t where rownum<=5;


顺序/倒序排列:
select * from t order by f1,f2 asc/desc;


按照字段求和:
select sum(f2) from t1 group by f1;
联合多表时使用having代替where:
having avg(f1)>50;


合并俩个列显示:
select f1||':'||f2 as f12 from t;


备份表数据:
create table t2 as select * from t1;


从其他表插入数据:
insert into t2 select * from t2;


求某列平均数:
select avg(f1) from t1;


求行数:
select count(*/f1) from t1;


求最大/最小值:
select max/min(f1) from t1;


浮点型数据四舍五入:
select round(f5,2) from t1;


数据加入:
select *from t1 inner/left/right/full join t2 on t1.f1=t2.f2;


数据联合(俩个表列数需相同):
select f1,f4 fromt1 union select f1,f2 from t2;


数据截取:
select substr(f1,1,3) from t1;
update t1 set f1=substr(f2,1,3)||'say'||substr(f3,7);

关于本篇内容如有转载请注明出处;技术内容的探讨、纠错,请发邮件到70907583@qq.com
原文地址:https://www.cnblogs.com/watertaro/p/9220769.html