产生任意的随机三条数据
order by dbms_random.value(1,50),再嵌套一层rownumselect * from (select rownum, empno from (select empno from emp order by dbms_random.value(1, 50))) where rownum <= 3;测试结果:SQL> select * 2 from (select rownum, e...
SYS_CONNECT_BY_PATH函数
SQL> select sys_connect_by_path(empno,',') from emp start with mgr is null connect by priSYS_CONNECT_BY_PATH(EMPNO,',')-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------...
分析函数avg(xx) over(partition by xxx order by x)
计算员工表中每个员工的平均薪水报告,该平均值由当前员工和与之具有相同经理的前一个和后一个三者的平均数得来select row_number() over(partition by mgr order by empno) rn, empno, mgr, avg(sal) over(partition by mgr orde...
给一个朋友看的一个题,题不难
(1)merge into t1using t2on (t1.no + 199 = t2.no)when matched then update set t1.区县 = t2.区县;(2)update /*+ leading(t2) use_hash(t1) */ t1 set 区县 = (select 区县 from t2 where t1.no + 199 = t2.no);(3)至少有一个表的连接列是主键...
每日一练(四)
第一个题:环境准备:drop table teachers;drop table students;drop table classes;create table Teachers(T_ID int,T_NAME varchar2(20));create table Students(S_ID int,S_NAME varchar2(20));create table Classes(T_ID int,S_ID int,C_NAME varchar2(20));insert into Teachers values(1,'T1');insert into ...
每日一练(三)按产品分类,仅列出各类商品中红色多于蓝色的商品名称及差额数量
产品 颜色 数量产品1 红色 100产品1 蓝色 80产品2 蓝色 103产品2 红色 NULL产品2 红色 89产品1 红色 100按产品分类,仅列出各类商品中红色多于蓝色的商品名称及差额数量drop table products;create table products(name v...
每日一练(二)decode函数
drop table userinfo;drop table checkinfo;create table userinfo(id int,username varchar2(32),u_id int);create table checkinfo(id int,checktype varchar2(32),u_id int);insert into userinfo values(1,'张三',1);insert into userinfo values(2,'李四',2);insert into userinfo values(3,'王五',3);insert...
每日一练(三)一个union all的例子,三个题
表结构是这样的SNAME CNAME------------------------- -------------------------张三 数学张三 &nb...
看到论坛发的一个面试题,觉得还是不错的,整理下来
用一条sql求出每个部门(emp表)的最大工资和最小工资,以及最大工资和最小工资的员工姓名。(注:一次表扫描。同一个部门最大工资或最小工资的人可能不止一个)。(1)如果没有后边的扫描表一次就会有很多的方法可以写出需求select empno, ename, sal max_sal, null min_sal from (select empno, &n...
查找重复数据,过滤重复数据
1、表:ee(id,name,age)要求:列出所有名字重复的人的记录 select name from ee group by name having count(*)>=2;NAME-------------------------Zhang3Wang1Zhang1Zhang22、有表:ee(name,age)name ageTom 16Sun 14Tom 16Tom 16要求:过滤掉所有多余的重复记录建表语句:create ta...