bd_ejempplos

2
1.-Problem 1 List employee number, last name, date of birth, and salary for all employees who make more than $30,000 a year. Sequence the results in descending order by salary. select empno as "Numero de empleado", lastname as APELLIDO, birthdate as "Fecha de nacimiento", salary as SALARIO from employee where salary>30000 order by salary DESC; Problem 2 List last name, first name, and the department number for all employees. The listing should be ordered by descending department numbers. Within the same department, the last names should be sorted in descending order. select lastname, firstnme, workdept from employee order by workdept desc, lastname desc; select lastname, firstnme, workdept from employee order by workdept desc, lastname; Problem 3 List the different education levels in the company in descending order. List only one occurrence of duplicate result rows. select edlevel from employee order by edlevel; select distinct edlevel from employee order by edlevel; select edlevel from employee group by edlevel; Problem 4 List employees, by employee number, and their assigned projects, by project number. Display only those employees with an employee number less than or equal to 100. List only one occurrence of duplicate rows. Sort the result rows by employee number. (Use the EMPprojACT table.) select distinct empno, projno from empprojact where empno<=100 order by empno; Problem 5 List last name salary, and bonus of all male employees. select lastname as apellido, sex as genero, salary as salario, bonus as bono from employee where sex="M"; Problem 6 List last name, salary, and commission for all employees with a salary greater than $20,000 and hired after 1979. select lastname, salary, comm, hiredate from employee where salary>40000 and hiredate>"1979-12-31"; Problem 7 List last name, salary, bonus, and commission for all employees with a salary greater than $22,000 and a bonus of $400, or for all employees with a bonus of $500 and a commission lower than $1,900. The list should be ordered by last name. select lastname, salary, bonus, comm from employee where salary>22000 and bonus=400 or bonus=500 and comm<1900 order by lastname; Problem 8 List last name, salary, bonus, and commission for all employees with a salary greater than $22,000, a bonus

Upload: gabriela-vargas

Post on 05-Mar-2015

54 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: BD_ejempplos

1.-Problem 1 List employee number, last name, date of birth, and salary for all employees who make more than $30,000 a year. Sequence the results in descending order by salary. select empno as "Numero de empleado", lastname as APELLIDO, birthdate as "Fecha de nacimiento", salary as SALARIO from employee where salary>30000 order by salary DESC; Problem 2 List last name, first name, and the department number for all employees. The listing should be ordered by descending department numbers. Within the same department, the last names should be sorted in descending order. select lastname, firstnme, workdept from employee order by workdept desc, lastname desc; select lastname, firstnme, workdept from employee order by workdept desc, lastname; Problem 3 List the different education levels in the company in descending order. List only one occurrence of duplicate result rows. select edlevel from employee order by edlevel; select distinct edlevel from employee order by edlevel; select edlevel from employee group by edlevel; Problem 4 List employees, by employee number, and their assigned projects, by project number. Display only

those employees with an employee number less than or equal to 100. List only one occurrence of duplicate rows. Sort the result rows by employee number. (Use the EMPprojACT table.) select distinct empno, projno from empprojact where empno<=100 order by empno; Problem 5 List last name salary, and bonus of all male employees. select lastname as apellido, sex as genero, salary as salario, bonus as bono from employee where sex="M"; Problem 6 List last name, salary, and commission for all employees with a salary greater than $20,000 and hired after 1979. select lastname, salary, comm, hiredate from employee where salary>40000 and hiredate>"1979-12-31"; Problem 7 List last name, salary, bonus, and commission for all employees with a salary greater than $22,000 and a bonus of $400, or for all employees with a bonus of $500 and a commission lower than $1,900. The list should be ordered by last name. select lastname, salary, bonus, comm from employee where salary>22000 and bonus=400 or bonus=500 and comm<1900 order by lastname; Problem 8 List last name, salary, bonus, and commission for all employees with a salary greater than $22,000, a bonus

Page 2: BD_ejempplos

of $400 or $500, and a commission less than $1,900. The list should be ordered by last name. select lastname, salary, bonus, comm from employee where salary>22000 and (bonus=400 or bonus=500) and comm<1900 order by lastname; Problem 9 Using the EMPPROJACT table, for all projects that have a project number beginning with AD and have activities 10, 80, or 180 associated with them, list the following: •Project number •Activity number •Starting date for activity •Ending date for activity Order the list by activity number within project number. select projno, actno, emstdate, emendate from empprojact where projno like "AD%" order by projno, actno; select projno, actno, emstdate, emendate from empprojact where projno like "AD%" and actno=10 or actno=80 or actno=180 order by projno, actno; select projno, actno, emstdate, emendate from empprojact where projno like "AD%" and actno IN(10, 80, 180) order by projno, actno; Problem 10 List manager number and department number for all departments to which a manager has been assigned. The list should be ordered by manager number. select mgrno, deptno from department where mgrno is not null order by mgrno; Problem 11

List employee number, last name, salary, and bonus for all employees that have a bonus ranging from $800 to $1,000. Sort the report by employee number within bonus, lowest bonus first. select empno, lastname, salary, bonus from employee where bonus between 800 and 1000 order by bonus, empno ; Problem 12 List employee number, last name, salary, and department number for all employees in departments A00 through C01 (inclusive). Order the results alphabetically by last name and employee number. select empno, lastname, salary, workdept from employee where workdept between "A00" and "C01" order by empno, lastname; Problem 13 List all projects that have SUPPORT as part of the project name. Order the results by project number. select projno, projname from project where projname like "% SUPP%" order by projno; Problem 14 List all departments that have a 1 as the middle character in the department number. Order the results by department number. select workdept from employee where workdept like "_1_"; Problem 15 List the last name, first name, middle initial, and salary of the five highest paid non-manager, nonpresident employees. Order the results by highest salary first. select lastname, firstnme, midinit, salary, job from employee where job not in("pres", "manager");