日期:2014-05-17 浏览次数:21048 次
--用户表 create table user_info ( u_id int primary key,--用户id u_name varchar2(20),--姓名 Department_id int ,--部门id Position_id int ,--职位id ) --到账记录表 create table user_yes_info ( u_id int , fee float,--金额 theMonth varchar(10)--月份 ) --待发记录表 create table user_waiting_info ( u_id int , fee float,--金额 theMonth varchar(10)--月份 ) --部门表 create table Department_info ( Department_id int primary key , Department_name varchar2(50) ) --职位表 create table Position_info ( Position_id int primary key , Position_name varchar2(50) )
select ui.u_name, (select Department_name from Department_info where Department_id=ui.Department_id) as Department_name, (select Position_name from Position_info where Position_id=ui.Position_id) as Position_name, sum(nvl(uyi.fee,0))+sum(nvl(uw.fee,0)) as sum_fee, sum(nvl(uyi.fee,0) as yes_fee, sum(nvl(uw.fee,0)) as waiting_fee, sum(nvl(muyi.fee,0))+sum(nvl(muw.fee,0)) as thismonth_sum_fee, sum(nvl(muyi.fee,0)) as thismonth_yes_fee, sum(nvl(muw.fee,0)) as thismonth_waiting_fee, from user_info ui left join user_yes_info uyi on uyi.u_id=ui.u_id left join user_waiting_info uw on uw.u_id=ui.u_id left join (select fee,u_id from user_yes_info where theMonth='11') muyi on muyi.u_id=ui.u_id left join (select fee,u_id from user_waiting_info where theMonth='11') muw on muw.u_id=ui.u_id
------解决方案--------------------
貌似我写的简单一点
select u_name as 姓名,department_name as 部门 ,position_name as 职位 ,
'请指明计算公式' as 总金额累计,incomeTotal as 到账金额累计,payTotal as 待发金额累计,
'请指明计算公式1' as 本月总金额,incomeTotalThis as 本月到账金额,payTotalThis as 本月待发金额
from
(
select u.u_id,u.u_name, d.department_name, p.position_name
from user_info u, Department_info d, Position_info p
where u.Department_id = d.Department_id
and u.Position_id = p.Position_id
) employee left join
(
select u_id,