甲骨文中的非常查询(高级人员入内)

pandengesen 2007-05-10 09:26:39
二、操作题(用SQL或Oracle)
1.某公司的员工工资表和部门情况表的表结构如下:
员工号 姓名 工资 工资月份 部门号
表A 员工工资表
部门号 部门名称 部门经理
表B 部门情况表
现以200604一个月的工资情况为例,用查询语句完成下列问题:
1)找出当月工资最高的员工的员工号、姓名、部门名称和工资;
2)找出当月工资最高的员工所在的部门的所有员工的平均工资;
3)找出公司各部门的部门号、部门名称和其员工当月的平均工资。
2.表C中只有一列COL001,每条记录由字符构成。现在知道每条记录中字符内容由8项组成,每项之间用‘;’隔开,8项之中有的项可能没有。试将COL001分成8列生成一张新表,原表中的每项为新表中的一列。
COL001
86130004;000100971;01060;;
8613000219;000100122;00110;8613000219
8613000310;000100122;0AAAA;;1013089;214
表C片断
1)画出你的解决方法的流程图、
2)写主要的代码
...全文
681 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
pandengesen 2007-05-14
  • 打赏
  • 举报
回复
各位谢了。潘石向你们母亲道声迟来的问候:母亲节快乐!
heyixiang 2007-05-13
  • 打赏
  • 举报
回复
f_split函数示例


http://blog.csdn.net/heyixiang/archive/2005/11/12/527973.aspx
kondin 2007-05-12
  • 打赏
  • 举报
回复
1)
select t1.员工号, t1.姓名 , t2.部门名称, t1.工资 from (select 员工号,姓名,工资,部门号 from 表A where 月份=to_char(sysdate,'MM')) t1,表B t2 where t1.工资=max(t1.工资) and ti.部门号=t2.部门号
2)
select avg(工资) 平均工资 from (select 员工号,姓名,工资,部门号 from 表A where 月份=to_char(sysdate,'MM') t1 where 部门 in (select 部门 from t1 where 工资=max(t1.工资));
3)select t1.部门号,t2.部门名称,平均工资 from (select 部门号,avg(工资) 平均工资 from (select 工资,部门号 from 表A where 月份=to_char(sysdate,'MM'))) t1,表2 t2 where t1.部门号=t2.部门号

下面那个 不知道了```
heyixiang(子豚の愛人)
能不能举个例子说明一下F_SPLIT函数的用法啊````谢谢啦``


kondin 2007-05-11
  • 打赏
  • 举报
回复
按时的
heyixiang 2007-05-11
  • 打赏
  • 举报
回复
如果COL001固定为8段,那么直接用substr就可以了

如果COL001段数不固定,那么就写一个f_split函数,然后循环处理。
pandengesen 2007-05-11
  • 打赏
  • 举报
回复
netstring,你写的语句怎么都报错啊?运行不了啊。能否帮忙改改。谢谢。
pandengesen 2007-05-10
  • 打赏
  • 举报
回复
就是因为小弟没有书,所以请教各位哈。能否帮我考虑下。谢谢各位,尤其是(想跳了...)。就是能体现出当月的。我现在才开始入门了。
netstring 2007-05-10
  • 打赏
  • 举报
回复
当月的可以自己过滤一下
pandengesen 2007-05-10
  • 打赏
  • 举报
回复
谢谢。美中不足是没有体现出当月哦。
netstring 2007-05-10
  • 打赏
  • 举报
回复
1) 没有什么流程图可画, 这些都是基本的SQL语句。
2)
1. select t1.员工号, t1.姓名 , t2.部门名称, t1.工资 from 表A t1, 表B t2 where t1.员工号 in (select max(工资) from 表A) and t1.部门号 = t2.部门号

2. select t2.部门号, avg(t1.工资) 平均工资 from 表A t1, 表B t2 where t1.员工号 in (select max(工资) from 表A) and t1.部门号 = t2.部门号 group by t1.部门号

3. select b.部门号, b.部门名称, avg(a.平均工资) 平均工资 from (select 部门号, avg(工资) 平均工资 from 表A group by 部门号) a, 表B b where a.部门号 = b.部门号

4. create table 表C (...);
insert into 表C select substr('8613000219;000100122;00110;8613000219' || ';',1,instr('8613000219;000100122;00110;8613000219' || ';',';',1,1) - 1) a,
substr('8613000219;000100122;00110;8613000219' || ';',instr('8613000219;000100122;00110;8613000219' || ';',';',1,1) + 1, instr('8613000219;000100122;00110;8613000219' || ';',';',1,2) - instr('8613000219;000100122;00110;8613000219' || ';',';',1,1) -1) b,
substr('8613000219;000100122;00110;8613000219' || ';',instr('8613000219;000100122;00110;8613000219' || ';',';',1,2) + 1, instr('8613000219;000100122;00110;8613000219' || ';',';',1,3) - instr('8613000219;000100122;00110;8613000219' || ';',';',1,2) -1) c,
substr('8613000219;000100122;00110;8613000219' || ';',instr('8613000219;000100122;00110;8613000219' || ';',';',1,3) + 1, instr('8613000219;000100122;00110;8613000219' || ';',';',1,4) - instr('8613000219;000100122;00110;8613000219' || ';',';',1,3) -1) d,
substr('8613000219;000100122;00110;8613000219' || ';',instr('8613000219;000100122;00110;8613000219' || ';',';',1,4) + 1, instr('8613000219;000100122;00110;8613000219' || ';',';',1,5) - instr('8613000219;000100122;00110;8613000219' || ';',';',1,4) -1) e,
substr('8613000219;000100122;00110;8613000219' || ';',instr('8613000219;000100122;00110;8613000219' || ';',';',1,5) + 1, instr('8613000219;000100122;00110;8613000219' || ';',';',1,6) - instr('8613000219;000100122;00110;8613000219' || ';',';',1,5) -1) f,
substr('8613000219;000100122;00110;8613000219' || ';',instr('8613000219;000100122;00110;8613000219' || ';',';',1,6) + 1, instr('8613000219;000100122;00110;8613000219' || ';',';',1,7) - instr('8613000219;000100122;00110;8613000219' || ';',';',1,6) -1) g,
substr('8613000219;000100122;00110;8613000219' || ';',instr('8613000219;000100122;00110;8613000219' || ';',';',1,7) + 1, instr('8613000219;000100122;00110;8613000219' || ';',';',1,8) - instr('8613000219;000100122;00110;8613000219' || ';',';',1,7) -1) h from dual

另外, 这不是什么非常查询, 都是一些基本SQL。

3,491

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 高级技术相关讨论专区
社区管理员
  • 高级技术社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧