7-23 learning database

orcal

third chapter

Exercise 1

 1. Query job is SALESMAN employee number, title, entry date.

 select empno,job,hiredate  from emp  where job = 'SALESMAN';

 2. Query entry before December 31, 1985 the employee name and hire date.

 select ename,hiredate  from emp  where hiredate = '31-12月-85';

 3. department employee name query number is not 10 departments, department number.

 select ename,deptno  from emp  where not deptno =10;

Exercise 2

 1. query entry date the employee's name in 82 years to 85 years, the entry date.

 select ename,hiredate  from emp  where hiredate in ('01-1月-82','31-12月-85');  

2. Query monthly salary in the 3000-5000 employee name, salary.

 select ename,sal  from emp  where sal in (3000,5000);

 3. Query department number for the employee name 10 or 20, the department number.

 select ename,deptno  from emp  where deptno in (10,20);  --where deptno =10 or deptno = 20;

 4. Query Manager numbered 7902, employee name 7566, 7788, and manager number.

 select ename,mgr  from emp  where mgr in (7902,7566,7788);  

5. Query employee name begins with W's employee name.

 select ename  from emp  where ename like 'W%';

 6. employee name query penultimate two characters for the name of the employee T's.

 select ename  from emp  where ename like '%T_';

 7. Query bonus empty employee name, bonus.

 select ename,comm  from emp  where comm is null;

Exercise 3

 1. Query wage jobs over 2000 and is MANAGER, or post a SALESMAN employee name, job title, salary

 select ename,job,sal  from emp  where (sal>2000 and job ='MANAGER') or job = 'SALESMAN';

 2. Query wage jobs over 2000 and is MANAGER SALESMAN or employee name, job title, salary.

 select ename,job,sal  from emp  where sal>2000 and (job ='MANAGER' and job ='SALSMAN');  

3. Query sector 10 or 20, the names and salaries of employees between 3000-5000, department, salary.

 select ename,deptno,sal  from emp  where deptno in (10,20) and sal in (3000,5000);  

4. query entry date in 81 years, and the post is not the beginning of the SALES employee name, hire date, position.

 select ename,hiredate,job  from emp  where hiredate in ('01-1月-81','31-12月-81') and job not like 'SALES%';  

The search jobs number SALESMAN or MANAGER, sector 10 or 20, containing employee names A name, title, department number.

 select ename,job,deptno  from emp  where job = 'SALESMAN' or job='MANAGER' and deptno in(10,20) and ename like '%A%';

Exercise 4

 1. Query department employee name 20 or 30, department number, and sorted by ascending wages.

 select ename,deptno  from emp  where deptno in(10,20)  order by sal;

 2. Query wages between 2000-3000, the employee's name is not on the 10th department, department number, wages, and sorted by department ascending, descending wages.

 select ename,deptno,sal  from emp  where sal in(2000,3000) and not deptno =10  order by deptno,sal desc;

 3. query entry date between 82 years to 83 years, or posts to SALES employee names beginning with MAN, hire date, position, and in accordance with the entry date in descending order.

 select ename,hiredate,job  from emp  where hiredate in('01-1月-82','31-12月-83') and (job like 'SALES%'or job like 'MAN%')  order by hiredate desc;

Homework [will do questions]

1. query entry time after 1982-7-9 and do not engage in work SALESMAN employee name, entry time jobs.

 select ename,hiredate,job  from emp  where hiredate>'09=7月-82' and not job ='SALESMAN';

2. Query the employees name of the third letter is a staff name.

 select ename  from emp  where ename like '__a%';

3. In addition to the employee name query 10,20 department, department number.

 select ename,deptno  from emp  where  not deptno in (10,20);

4. Query information department number is 30 employees, press wages in descending order, then name ascending order.

 select *  from emp  where deptno =30  order by sal desc,ename;

5. Query no employees of upper management (manager number is empty) the name of the employee, the higher number.

 select ename,mgr  from emp  where mgr is null;

6. queries wages than or equal to 4500 and for the staff department of 50 or 60 names \ wages, department number.

 select ename,sal,deptno  from emp  where sal>=4500 and deptno in (50,60);

 

chapter Five

Exercise 1

 1. Write a query that displays all the employee's name, department number, department name.

 select ename,emp.deptno,dname    from emp,dept    where emp.deptno=dept.deptno;

 2. Write a query to display all work in CHICAGO bonus is not empty and the employee name, place of work, bonuses

 select ename,loc,comm    from emp,dept    where emp.deptno = dept.deptno and (loc = 'CHICAGO' )and not ( comm  is null);

 3. Write a query that displays all the names in the employee's name contains the character A, place of work  

select ename,loc  from emp,dept  where emp.deptno = dept.deptno and ename like '%A%';

 

Exercise 2  

1. queries each employee number, name, salary, wage levels, where the work of the city, in ascending order according to the wage scale.

 select empno,ename,sal,grade,loc  from emp,dept,salgrade  where emp.deptno = dept.deptno and emp.sal between salgrade.losal and salgrade.hisal  order by grade;

Exercise 3

 1. queries all employees work in the name of NEW YORK and CHICAGO, employee number, and the name of their manager, manager Number  

select a.ename,a.empno,b.ename,b.empno  from emp a,emp b,dept  where a.mgr=b.empno and loc in('NEWYORK','CHICAGO');

 2. On the basis of the first question, there is no manager's staff add King, and sorted by number of employees  

select a.ename,a.empno,b.ename,b.empno   from emp a,emp b    where a.mgr=b.empno(+)    order by a.empno;

 

Exercise 4

 Written using the SQL-99, complete the following exercises

 1. Create a cross-connect employee table and the department table.

 select * from emp CROSS join dept;

 2. Use natural connection, displays the entry date the employee's name after 80 years May 1, the department name, the date of entry

 select ename,dname,hiredate from emp NATURAL join dept   where  hiredate >'01-5月-80';  

3. Use the USING clause, display the work of employee names in CHICAGO, department name, place of work

 select ename,dname,loc from emp join dept  using(deptno) where loc='CHICAGO';

 4. Use the ON clause to show working CHICAGO employee name, department name, place of work, salary level in

 select ename,dname,loc,grade from emp  join dept on emp.deptno=dept.deptno   join salgrade on sal between losal and hisal and loc='CHICAGO';

 5. Use the left join, the query name of each employee, manager name, manager of the King did not have to show up.

 select a.ename ,b.ename  from emp a left outer join emp b  on a.mgr = b.empno;       

 6. Use the right connections, query the name of each employee, manager name, manager of the King did not have to show up.

 select a.ename,b.ename  from emp a right outer join emp b  on a.empno=b.mgr;

 

after class homework

 1. Display SMITH employee's name, department name, the name of the direct supervisor

 select a.ename,a.deptno,b.ename  from emp a,emp b  where a.mgr=b.empno and a.ename ='SMITH';  

 2. Display the employee name, department name, salary, wage levels, wage levels greater than the required level 4.

 select ename,dname,sal,grade  from emp,dept,salgrade  where emp.deptno=dept.deptno and sal between losal and hisal and grade>4;

 3. Display the employee name and employee KING FORD management and its manager name.

 select a.ename,b.ename,c.ename  from emp a,emp b,emp c  where (a.ename='KING'or a.ename='FORD')  and (a.empno=b.mgr) and (a.mgr=c.empno(+));

 4. Display the employee name, time to work, manager name, time to work, he asked to participate earlier than manager.

 select a.ename,a.hiredate,b.ename,b.hiredate  from emp a,emp b  where a.mgr=b.empno and a.hiredate<b.hiredate;

 

mysql

Chapter Six

Exercise 1

1. Write a query that displays all the employee's name, department number, department name.

 select ename,emp.deptno,dname  from emp,dept  where emp.deptno=dept.deptno;

2. Write a query to display all work in CHICAGO bonus is not empty and the employee name, place of work, bonuses

 select ename,loc,comm  from emp,dept  where emp.deptno=dept.deptno and loc='CHICAGO' and comm is null;

3. Write a query that displays all the names in the employee's name contains the character A, place of work.

 select ename,loc  from emp,dept  where emp.deptno= dept.deptno and ename like '%A%';

 

Exercise 2

1. queries each employee number, name, salary, wage levels, where the work of the city, in ascending order according to the wage scale.  

select empno,ename,sal,grade,loc  from emp,dept,salgrade  where emp.deptno=dept.deptno and sal between losal and hisal  order by grade;

 

Exercise 3

1. queries all employees work in the name of NEW YORK and CHICAGO, employee number, and the name of their manager, manager number.

 select a.ename,a.empno,b.ename,b.empno  from emp a,emp b,dept  where (loc ='NEW YORK' or loc ='CHICAGO') and (a.deptno=dept.deptno) and a.mgr=b.empno ;

 

Exercise 4

1. Using SQL-99 wording, complete the following exercises 1. Create a cross employee table and the department table connection.

 select * from emp CROSS join dept;

2. Use natural connection, displays the entry date the employee's name after 80 years May 1, the department name, the date of entry

 select emp.ename,dept.dname,emp.hiredate  from emp NATURNAL join dept  where emp.deptno=dept.deptno and emp.hiredate>'1980-5-1';

3. Use the USING clause, display the work of employee names in CHICAGO, department name, place of work

 select ename,dname,loc  from emp join dept  using(deptno) where loc='CHICAGO';

4. Use the ON clause to show working CHICAGO employee name, department name, place of work, salary level in

 select ename ,dname,loc,grade  from emp join dept on emp.deptno=dept.deptno  join salgrade on sal between losal and hisal and loc='CHICAGO';

5. Use the left join, the query name of each employee, manager name, manager of the King did not have to show up.

 select a.ename,b.ename  from emp a left outer join emp b  on a.mgr=b.empno;

6. Use the right connections, query the name of each employee, manager name, manager of the King did not have to show up.

 select a.ename,b.ename  from emp a right outer join emp b  on a.empno= b.mgr;

 

after class homework

1. Display SMITH employee's name, department name, the name of the direct supervisor

 select a.ename,dname,b.ename  from emp a,emp b,dept  where a.deptno=dept.deptno and a.mgr=b.empno and a.ename = 'SMITH';

2. Display the employee name, department name, salary, wage levels, wage levels greater than the required level 4.

 select ename,dname,sal,grade  from emp,dept,salgrade  where emp.deptno=dept.deptno and sal between losal and hisal and grade>4;

 3. Display the employee name and employee KING FORD management and its manager name.

 select a.ename,b.ename,c.ename  from emp a left outer join emp c join emp b  on (a.ename ='KING' or a.ename= 'FORD') and a.empno=b.mgr and a.mgr=c.empno;

4. Display the employee name, time to work, manager name, time to work, he asked to participate earlier than manager.

 select a.ename,a.hiredate,b.ename,b.hiredate  from emp a,emp b  on a.mgr=b.empno and a.hiredate<b.hiredate;

Guess you like

Origin www.cnblogs.com/hole/p/11234388.html