Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php sqlplus中的嵌套查询_Php_Sql_Sql Server_Database - Fatal编程技术网

Php sqlplus中的嵌套查询

Php sqlplus中的嵌套查询,php,sql,sql-server,database,Php,Sql,Sql Server,Database,我需要创建一个名为salary的新表,它包含两列:第一列是e_id,第二列是salary 但首先我需要根据这个等式计算每个员工的工资 Sal=e_bsal+suma_val–sumd_val您的问题标题是SQL plus;意思是甲骨文。您正在为mysql和MSSQL添加标记。选择employee.e_id,employee.e_bsal+子问题1.total_allow-subqueary2.total_从employee中扣除,选择e_id,suma_val作为总允许从津贴中扣除,津贴交易,其

我需要创建一个名为salary的新表,它包含两列:第一列是e_id,第二列是salary

但首先我需要根据这个等式计算每个员工的工资


Sal=e_bsal+suma_val–sumd_val

您的问题标题是SQL plus;意思是甲骨文。您正在为mysql和MSSQL添加标记。选择employee.e_id,employee.e_bsal+子问题1.total_allow-subqueary2.total_从employee中扣除,选择e_id,suma_val作为总允许从津贴中扣除,津贴交易,其中津贴.a_id=津贴,按e_id子项1交易,a_id分组,其中子项1.e_id=员工.e_id,并选择e_id,sumd_val作为从扣除中扣除的总额,扣除交易,其中扣除.d_id=按e_id子项2扣除,其中子项2.e_id=员工.e_id;按e_id分组第12行的子问题2错误:ORA-00936:缺少表达式您可以对表格和数据进行修改吗
create table Employee(e_id number(6) primary key , e_name varchar2(3),e_dept varchar2(30),e_bsal number(10));

create table Allowance(a_id number(6) primary key , a_name varchar2(30),a_val  number(10));

create table Deduct(d_id number(6) primary key , d_name varchar2(30) , d_val number(10));

create table Deduct_trans(e_id number(6), d_id number(6),
constraint e_id_pk foreign key(e_id) references Employee(e_id),
constraint d_id_pk foreign key(d_id) references Deduct(d_id));

create table Allowance_trans(e_id number(6),a_id number(6),
constraint e_id_2_pk foreign key(e_id) references Employee(e_id),
constraint a_id_pk foreign key(a_id) references Allowance(a_id));

create table Salary(e_id number(6),sal number(30),
constraint e_id_3_pk foreign key(e_id) references Employee(e_id));

insert into Employee values(1,'a','Fin',200);
insert into Employee values(2,'b','Pers',220);
insert into Employee values(3,'c','stu',250);

insert into Allowance values(1,'Transpo',100);
insert into Allowance values(2,'Univ',400);
insert into Allowance values(3,'Family',50);
insert into Allowance values(4,'other',250);

insert into Deduct values(1,'Insur',30);
insert into Deduct values(2,'Tax',50);
insert into Deduct values(3,'Secu',60);
insert into Deduct values(4,'socila',10);

insert into Allowance_trans values(1,1);
insert into Allowance_trans values(1,2);
insert into Allowance_trans values(1,3);
insert into Allowance_trans values(2,1);
insert into Allowance_trans values(2,2);
insert into Allowance_trans values(2,3);

insert into Deduct_trans values(1,1);
insert into Deduct_trans values(1,2);
insert into Deduct_trans values(1,3);
insert into Deduct_trans values(2,1);
insert into Deduct_trans values(2,2);
insert into Deduct_trans values(2,3);
insert into Deduct_trans values(2,4);
SELECT E.e_id,( E.e_bsal +total_aval - total_dval ) as Salary
FROM Employee E
INNER JOIN    
( 
  SELECT e_id,SUM(a_val) as total_aval
  FROM Allowance A
  INNER JOIN Allowance_trans AT
    ON AT.a_id=A.a_id
  GROUP BY AT.e_id
) t1

ON t1.e_id=E.e_id

INNER JOIN

( 
  SELECT e_id,SUM(d_val) as total_dval
  FROM Deduct D
  INNER JOIN Deduct_trans DT
  ON D.d_id=DT.d_id
  GROUP BY DT.e_id
) t2

ON t2.e_id=E.e_id