首页 > 试题广场 >

一、数据库 下面是两个数据库表,分别记录员工姓

[问答题]

一、数据库


下面是两个数据库表,分别记录员工姓名和员工工资:

T_EMPLOYEE

ID

NAME

GMT_CREATE

GMT_MODIFY

2

张三

2014-03-04

2014-03-04

3

李四

2014-03-15

2014-06-07

5

王五

2014-03-04

2014-07-04

·····

·····

·····

·····

注:NAME唯一

T_SALARY

EMPLOYEE_ID

SALARY

MONTH

GMT_CREATE

2

3400

201403

2014-03-26

3

4300

201403

2014-03-26

2

3400

201404

2014-04-26

·····

·····

·····

·····

请编写SQL解决以下问题:

1)  查询表 T_EMPLOYEE id = 3 的员工记录


2)  查询20143月份所有员工薪水,SALARY从高到低排列

NAME

SALARY

MONTH

3)  增加员工“王五”20145月份工资为3000的记录,GMT_CREATE时间取数据库系统时间


4)  查询20144月份未发工资的员工姓名


5)  删除员工姓名为“李四”的员工信息和工资信息

3、INSERT INTO T_SALARY(EMPLOYEE_ID, SALARY, MONTH, GMT_CREATE) VALUES ((SELECT ID FROM T_EMPLOYEE WHERE NAME='王五'), 3000, 201403, CURDATE()) 4、DELETE T_EMPLOYEE, T_SALARY FROM T_EMPLOYEE A INNER JOIN T_SALARY B ON A.ID=B.EMPLOYEE_ID WHERE A.NAME='李四'
发表于 2019-09-17 17:01:22 回复(0)
1.
select * 
from T_EMPLOYEE
where id=3;
2.
select te.Name,ts.salary,ts.month
from T_EMPLOYEE te,T_SALARY ts
where te.ID = ts.EMPLOYEE_ID
and ts.month='201403'
order by salary desc;
3.
insert into T_SALARY (EMPLOYEE_ID,SALARY,MONTH,GMT_CREATE)
values((select ID from T_EMPLOYEE E where E.NAME='王五',3000,'201405',curdate()));

4.
select NAME
from T_EMPLOYEE E
where not exists(select 1 from T_SALARY S 
where E.ID=EMPLOYEE_ID 
and S.MONTH='201404');
5.
delete from T_EMPLOYEE E,T_SALARY S
where E.ID = S.EMPLOYEE_ID
and E.NAME='李四';

编辑于 2019-10-06 17:52:07 回复(0)
(1)
select *
from T_EMPLOYEE 
where id = 3;

(2)
select name, salary, month
from T_SALARY s, T_EMPLOYEE e
where month = '201405' and
	  s.EMPLOYEE_ID = e.ID
order by salary desc;


(3)
-- mysql  sysdate()  返回时间格式:2012-12-08 15:41:25
insert into T_SALARY(EMPLOYEE_ID, SALARY, MONTH, GMT_CREATE)
values((select id from T_EMPLOYEE where NAME = '王五'), 3000, '201405', sysdate());

-- oracle 获取的时间格式:
insert into T_SALARY(EMPLOYEE_ID, SALARY, MONTH, GMT_CREATE)
values((select id from T_EMPLOYEE where NAME = '王五'), 3000, '201405', sysdate);

-- mysql 符合题目时间格式
insert into T_SALARY(EMPLOYEE_ID, SALARY, MONTH, GMT_CREATE)
values((select id from T_EMPLOYEE where NAME = '王五'), 3000, '201405', current_date());

(4)
select name 
from T_EMPLOYEE
where id not in(select EMPLOYEE_ID
                from T_SALARY
                where MONTH = '201404');

(5)
delete from T_SALARY
where EMPLOYEE_ID = (select ID
                     from T_EMPLOYEE
                     where NAME = '李四');

delete from T_EMPLOYEE
where name = '李四';


-- 添加事务处理(oracle )
delete from T_SALARY
where EMPLOYEE_ID = (select ID
                     from T_EMPLOYEE
                     where NAME = '李四');

delete from T_EMPLOYEE
where name = '李四';

commit;

发表于 2022-02-23 14:37:32 回复(0)
1.select * from T_EMPLOYEE where id=3;
2.select NAME,SALARY,MONTH from T_EMPLOYEE e,T_SALARY s where e.ID=s.EMPLOYEE_ID and MONTH='201403' order by SALARY desc;
3.insert into table T_SALARY(EMPLOYEE_ID,SALARY,MONTH,GMT_CREATE) values(select ID from T_EMPLOYEE where NAME='王五',3000,201405,CURDATE);
4.select NAME from T_EMPLOYEE where ID not exists in (select EMPLOYEE_ID from T_SALARY where MONTH='201404');
5.delete from T_EMPLOYEE e,T_SALARY  s where e.ID=s.ID and  NAME='李四'; 
发表于 2020-10-06 12:30:57 回复(0)

1、Select * from T_EMPLOYEE where id =3

2、Select a.NAME, b.SALARY, b.MONTH from T_EPLOYEE a,T_SALARY b where a.ID=b.EMPLOYEE_ID and b.MONTH=201403 order by b.SALARY desc

3、Insert into T_SALARY values(select ID from T_EMPLLOYEE where NAME=’王五’,3000,’201405’,curdate())

4、select NAME from T_EMPLOYEE E where no exits(select 1 from T_SALARY S where E.ID=S.EMPLOYEE_ID and S.MONTH=’201404’)

5、delect from T_EMPLOYEE E, T_SALARY S where E.ID=S.EMPLOYEE_ID and E.NAME=’李四’

发表于 2020-03-20 17:53:51 回复(0)