Sunteți pe pagina 1din 18

1.

a. b. c. d. e.

Which statement about joining tables with a non-equijoin is true?


A WHERE clause must specify a column in one table that directly corresponds to a column in the second table The tables being joined must NOT have any columns with the same name The number of join conditions required is always one less than the number of tables being joined No more than three tables can be joined using a non-equijoin The columns being joined must have compatible data types

Consider the following SELECT statement: SELECT ename, emp_number, salary FROM employee WHERE dept_number = (SELECT dept_number FROM department WHERE location IN('CHICAGO', 'NEW YORK')) Why does this statement return an error?
a. b. c. d. A multiple-row subquery returns one row A single-row subquery returns more than one row A multiple-column subquery returns one column A multiple-row query uses a single-row subquery

2.

Consider the following SELECT statement: SELECT ename, empno, sal FROM emp WHERE deptno = (SELECT deptno FROM dept WHERE UPPER(loc) = UPPER('&loc')) When executing this statement, what could be the result?
a. b. c. d. The statement executes successfully if the LOC column in the DEPT table has unique values The statement fails if the values returned from a multiple-row subquery are compared with an equality operator in the main query The statement fails because an ampersand (&) character cannot be used in the subquery of a SELECT statement The statement executes successfully, but does not return the expected results because of the use of the UPPER function twice in the subquery

3.

Examine the following statement: 4. SELECT empno_seq.CURRVAL FROM SYS.dual; Which value is displayed?
a. b. c. d. Current value of the EMPNO_SEQ sequence Current value of the EMPNO_SEQ cursor Values of the EMPNO_SEQ column Current value of the EMPNO_SEQ index

5.

If a database is queried with the following command: SELECT object_name FROM all_objects WHERE object_type = 'TABLE';

Which values are displayed?


a. b. c. d. Only the names of all the tables that can be accessed Only the names of all the objects that can be accessed Only the names of the objects that are owned Only the names of the tables that are owned

The ITEM table contains the following columns: ID NUMBER(7) PK SALE_PRICE NUMBER(7,2) Evaluate the following SQL statements: 6. 1.SELECT MAX(sale_price), MIN(sale_price), AVG(sale_price) FROM ITEM; 2.SELECT ROUND(MAX(sale_price),2), ROUND(MIN(sale_price),2), ROUND(AVG(sale_price),2) FROM ITEM GROUP BY sale_price; How will the results differ?
a. b. c. d. Statement 2 will only display one row of results; statement 1 could display more than one One of the statements will generate an error Statement 1 will display three values; statement 2 will display three values for each sale price Statement 1 will display a result for each sale price; statement 2 will display a result for each item

Consider the following SELECT statement: SELECT dept_no "Departments", MAX(salary) "Max Salaries" FROM employee WHERE dept_no IN(200, 300, 400) GROUP BY Departments HAVING MAX(salary) > 60000; Due to which clause does this statement fail?
a. b. c. d. Group By Where Select Having

7.

8.
a. b. c. d. e.

Which of the following commands cause a transaction to end?


DELETE ALTER INSERT UPDATE ROLLBACK

9.
a. b. c. d.

Which statements about data types are true?


The BLOB data type stores character data up to four gigabytes The TIMESTAMP data type is an extension of the VARCHAR2 data type The CHAR data type should be used for fixed-length character data The INTERVAL YEAR TO MONTH data type allows time to be stored as an interval of years and months

10.

Which of the following statements regarding the use of subqueries are true?

a. b. c. d. e.

A subquery used with the IN operator must return multiple rows A subquery can be used in a CREATE VIEW statement, regardless of the number of rows it returns A subquery can be used in the SET clause of an UPDATE statement, regardless of the number of rows it returns A subquery used in an INTO clause of a SELECT statement must return only one column, but can return multiple rows A subquery CANNOT be used in the GROUP BY clause of a SELECT statement

Evaluate the following SQL*Plus command: 11. START empdetail Which task will this command accomplish?
a. b. c. d. It runs the EMPDETAIL.SQL script file It creates the EMPDETAIL.SQL file using the default file extension It executes the EMPDETAIL.SQL PL/SQL routine It invokes the editor to edit the contents of the EMPDETAIL file

Evaluate the following SELECT statement: SELECT FROM WHERE emp_id, name emp emp_id NOT IN (SELECT emp_id FROM emp WHERE dept_id = 30 AND job = 'SALESMAN');

12.

What would happen if the inner query returned a NULL value?


a. b. c. d. No rows would be selected from the EMPLOYEE table A syntax error would be returned All the EMPLOYEE_ID and NAME values in the EMPLOYEE table would be displayed Only the rows with EMPLOYEE_ID values equal to NULL would be included in the results

13.
a. b. c. d. e.

In which clauses of a SELECT statement can substitution variables be used?


The SELECT and FROM clauses, but NOT the WHERE clause The SELECT, FROM, WHERE, and GROUP BY clauses, but NOT the ORDER BY clause The SELECT, WHERE, GROUP BY, and ORDER BY clauses, but NOT the FROM clause The SELECT and FROM clauses, but NOT the WHERE clause The SELECT, FROM, WHERE, GROUP BY, ORDER BY, and HAVING clauses

14.
a. b. c. d.

Which operators can be used in an outer join condition?


AND IN OR =

15.
a. b. c. d.

What is the correct use of the Trunc command on a date?


TRUNC=To_Date('09-Jan-02,DD-MON-YY,'YEAR',"Date" from Dual; Select TRUNC(To_Date('09-Jan-02,DD-MON-YY,YEAR')) "DATE" from Dual; Date =TRUNC(To_DATE('09-Jan-02','DD-MON-YY'),'YEAR'),'YEAR)"DATE: from DUAL; SELECT TRUNC(TO_DATE('12-Feb-99','DD-MON-YY'), 'YEAR') "Date " FROM DUAL;

16.
a. b. c. d. e.

Which type of join should be written to perform an outer join of tables A and B that returns all rows from B?
Any outer join A left outer join A cross join A right outer join An inner join

17.
a. b. c. d.

How many join conditions should be there to avoid a Cartesian Join for joining three tables?
1 2 3 None of the above

18.
a. b. c. d.

Which Data Dictionary view holds information about the column in a view?
USER_VIEWS USER_VIEW_COLUMNS USER_TAB_COLUMNS USER_ALL_COLUMNS

19.
a. b. c. d. e.

Which of the following views should a user query to display the columns associated with the Constraints on a table owned by the user?
USER_CONSTRAINTS USER_OBJECTS ALL_CONSTRAINTS USER_CONS_COLUMNS USER_COLUMNS

20.
a. b. c. d. e.

Which of the following SELECT statements will get the result 'ELCOME' from the string 'WELCOME'?
SELECT SUBSTR ('WELCOME',1) FROM dual; SELECT INITCAP(TRIM('WELCOME', 1,1) FROM dual; SELECT LOWER (SUBSTR ('WELCOME', 2,1) FROM dual; SELECT LOWER (SUBSTR('WELCOME', 2,1) FROM dual; SELECT LOWER (TRIM ('W' FROM 'WELCOME')) FROM dual;

21.
a. b. c. d.

Which script displays '01-MAR-03' when the JOIN_DATE value is '01-MAR02'?


SELECT FROM SELECT FROM SELECT FROM SELECT FROM ROUND(join_date, 'YEAR') Emp; ROUND(join_date, 'DAY') Emp; ROUND(join_date, 'MONTH') Emp; ROUND(TO_CHAR(join_date, 'YYYY')) Emp;

22.
a.

Evaluate the following statement: TRUNCATE TABLE product; Which of the following users can successfully issue this statement?
The owner of the INVENTORY table

b. c. d.

Any user with access to the PUBLIC schema Any user with the DELETE ANY TABLE system privilege Any member of the CONNECT and RESOURCE roles

23.
a. b. c. d.

What does SQL stand for?


Strong Question Language Structured Question Language Structured Query Language Start up Language

1.

Which SQL SELECT statement performs a projection, a selection, and join when executed?
SELECT id_number,seller_id FROM ITEM ORDER BY seller_id, id_number; SELECT id_number,seller_id FROM ITEM WHERE seller_id = 'F10032'; SELECT seller_id, city FROM SALLER AND seller_id = 'F10032' ORDER BY city; SELECT p.id_number, s.seller_id, seller.city FROM ITEM p, SALLER s WHERE p.seller_id = m.seller_id AND m.seller_id='F10032';

a.

b.

c.

d.

Which component is a literal in the following select statement? 2.


a. b. c. d.

Select 'Emp name :'||ename from emp where deptno=20;


ename. 20. emp name. ||.

5
a. b. c. d.

Which of the following SQL statement returns a numeric value?


SELECT ADD_MONTHS(MAX (hire_date), 6) FROM EMP; SELECT ROUND(hire_date)FROM EMP; SELECT sysdate-hire_date FROM EMP; SELECT TO_NUMBER(hire_date + 7)FROM EMP;

6.
a. b. c. d. e.

_______ operator can be used with a multiple row SubQuery.


= LIKE BETWEEN NOT IN Is

7.
a. b. c. d.

The names of the employees who have been with the company for more than five years is to be listed. Which of the following SQL statements will display the required results?
SELECT ENAME FROM EMP WHERE SYSDATE-HIRE_DATE>5 SELECT ENAME FROM EMP WHERE HIRE_DATE-SYSDATE > 5 SELECT ENAME FROM EMP WHERE (SYSDATE-HIRE_DATE)/365 > 5 SELECT ENAME FROM EMP WHERE (SYSDATE-HIRE_DATE)* 365 > 5

8.

Examine the structures of the EMPLOYEE and DEPARTMENT tables:

EMPLOYEE -----------------EMP_ID NUMBER NOT NULL PK NAME VARCHAR(30) NOT NULL FNAME VARCHAR(25) NOT NULL DEPT_NO NUMBER TITLE VARCHAR2(25) DEPARTMENT -----------------------DEPT_ID NUMBER NOT NULL PK DEPT_NAME VARCHAR2(25) A list of departments has to be created including the department name that have more than three administrative assistants. Which SELECT statement will produce the desired result?
SELECT d.dept_name FROM employee e JOIN department d ON (e.dept_no = d.dept_id) WHERE LOWER(title) = 'administrative assistant' GROUP BY dept_name HAVING COUNT(emp_id) > 3; SELECT dept_name FROM employee e JOIN department d ON (e.dept_no = d.dept_id) WHERE LOWER(title) = 'administrative assistant' AND COUNT(*) > 3; SELECT dept_name FROM employee NATURAL JOIN department WHERE LOWER(title) = 'administrative assistant' GROUP BY dept_name HAVING COUNT(emp_id) > 3; SELECT dept_name FROM employee GROUP BY dept_no HAVING LOWER(title) = 'administrative assistant' AND COUNT(*) > 3;

a.

b.

c.

d.

The PRODUCT table contains the following columns: PRODUCT_ID NUMBER(9) DESCRIPTION VARCHAR2(20) COST NUMBER(5,2) MANUFACTURER_ID VARCHAR2(10) The product costs needs to be displayed with the following results: 1. The cost displayed for each product is increased by 20 percent. 2. The product manufacturer id must be 5001, 5020, or 5050. 3. Twenty percent of the original cost is less than $4. Which statement should be used?
SELECT description, cost * 1.20 FROM product WHERE cost * .20 < 4 AND manufacturer_id = ('5001','5020','5050'); SELECT description, cost * .20 FROM product WHERE cost * .20 < 4.00 AND manufacturer_id BETWEEN '5001' AND '5050'; SELECT description, cost * 1.20 FROM product WHERE cost * .20 < 4.00 AND manufacturer_id IN ('5001', '5020', '5050'); SELECT description, cost * 1.20 FROM product WHERE cost * .20 < 4.00 AND manufacturer_id ANY('5001', '5020', '5050');

9.

a.

b.

c.

d.

Consider the following SELECT statement: SELECT emp_id, name FROM employee WHERE emp_id NOT IN (SELECT emp_id FROM employee WHERE depart_id = 30 AND job = 'CLERK'); What would happen if the inner query returned a NULL value?
a. b. c. d. No rows would be selected from the EMPLOYEE table A syntax error would be returned All the EMP_ID and NAME values in the EMPLOYEE table would be displayed Only the rows with EMP_ID values equal to NULL would be included in the results

10.

11.
a. b. c. d.

In a SELECT statement that includes a WHERE clause, where is the GROUP BY clause placed statement?
Immediately after the SELECT clause Before the WHERE clause After the ORDER BY clause After the WHERE clause

A database was queried with the following command: SELECT name, salary, dept_id FROM employee WHERE salary > (SELECT AVG(salary) FROM employee WHERE dept_no = (SELECT dept_no FROM employee WHERE last_name = (SELECT last_name FROM employee WHERE salary > 50000))); Which SELECT clause is evaluated first?
a. b. c. d. SELECT dept_no SELECT last_name SELECT name, salary, dept_id SELECT AVG(salary)

12.

13.
a. b. c. d.

find the name of the employee from emp table whose fname second charcter begins with 'e'
select * from emp where fname like'_e%' select * from emp where fname like'e%' select * from emp where fname like'_e' select * from emp where fname like'ae%'

1.
a. b. c. d.

Which Data Dictionary view holds information about the column in a view?
USER_VIEWS USER_VIEW_COLUMNS USER_TAB_COLUMNS USER_ALL_COLUMNS

2.
a. b. c. d. e. f.

Which of the following SQL statements should be used to remove a view called EMP_DEPT_VU from the schema?
DROP emp_dept_vu; DELETE emp_dept_vu; REMOVE emp_dept_vu; DROP VIEW emp_dept_vu; DELETE VIEW emp_dept_vu; REMOVE VIEW emp_dept_vu;

3.
a. b. c. d. e.

The STUDENTS table needs to be modified to add a primary key on the STUDENT_ID column. The table is currently empty. Which of the following statements will accomplish the task?
ALTER TABLE students ADD PRIMARY KEY student_id; ALTER TABLE students ADD CONSTRAINT PRIMARY KEY (student_id); ALTER TABLE students ADD CONSTRAINT stud_id_pk PRIMARY KEY student_id; ALTER TABLE students ADD CONSTRAINT stud_id_pk PRIMARY KEY (student_id); ALTER TABLE students MODIFY CONSTRAINT stud_id_pk PRIMARY KEY (student_id);

Examine the structure of the EMPLOYEES and NEW_EMPLOYEES tables given below: EMPLOYEES --------------------EMPLOYEE_ID NUMBER FIRST_NAME VARCHAR2 (20) LAST_NAME VARCHAR2 (20) HIRE_DATE DATE NEW_EMPLOYEES -----------------------EMPLOYEE_ID NUMBER NAME VARCHAR2 (40)

Primary Key

4.

Primary Key

Which of the following DELETE statements is valid?


a. b. c. d. DELETE FROM employees WHERE employee_id = (SELECT employee_id FROM employees); DELETE * FROM employees WHERE employee_id = (SELECT employee_id FROM new_employees); DELETE FROM employees WHERE employee_id IN (SELECT employee_id FROM new_employees WHERE name ='Carrey'); DELETE * FROM employees WHERE employee_id IN (SELECT employee_id FROM new_employees WHERE last_name ='Carrey'

5.
a. b. c. d. e. f.

Which of the following CREATE TABLE statements will fail?


CREATE TABLE time1 (time1 NUMBER(9)); CREATE TABLE time (time_id NUMBER(9)); CREATE TABLE date (time_id NUMBER(9)); CREATE TABLE time* (time_id NUMBER(9)); CREATE TABLE $time (time_id NUMBER(9)); CREATE TABLE datetime (time_id NUMBER(9));

6.
a. b. c. d.

What is the syntax for removing a PRIMARY KEY constraint and all its dependent constraints?
ALTER TABLE table_name REMOVE CONSTRAINT PRIMARY KEY CASCADE; ALTER TABLE table_name DROP PRIMARY KEY CASCADE; ALTER TABLE table_name DISABLE CONSTRAINT PRIMARY KEY CASCADE; A PRIMARY KEY constraint CANNOT be removed if it has dependent constraints

7.
a. b. c. d. e.

Which statement type would be used to remove transactions more than one year old from the TRX table?
DCL DML DDL TCL DRL

8.

The PRIMARY KEY constraint was disabled on the ID column in the Product table and all the values in the Product table were updated. The constraint is to be enabled and it should be verified that the new ID column values do not violate the constraint. If any of the ID column values do not conform to the constraint, an error message should be returned. Evaluate the following statement: ALTER TABLE product ENABLE CONSTRAINT product_id_pk; Which statement is true?

a. b. c. d.

The statement will execute, but will NOT enable the PRIMARY KEY constraint The statement will achieve the desired results The statement will execute, but will NOT verify that values in the ID column do NOT violate the constraint The statement will return a syntax error

9.

A user JOE needs to be created and this user should be allowed to create and drop tables in any schema. He should be able to create procedures and sequences only in his schema. Which script should be used to achieve these results?
CREATE USER joe IDENTIFIED BY joe123; GRANT DROP ANY TABLE, CREATE SEQUENCE, CREATE PROCEDURE TO joe CREATE USER joe

a.

b.

IDENTIFIED BY joe123; GRANT CREATE TABLE, DROP TABLE, CREATE SEQUENCE, CREATE PROCEDURE TO joe CREATE USER joe IDENTIFIED BY joe123; GRANT CREATE SESSION, CREATE ANY TABLE, DROP ANY TABLE, CREATE SEQUENCE, CREATE PROCEDURE TO joe CREATE USER joe IDENTIFIED BY joe123; GRANT CREATE SESSION, DROP ANY TABLE, CREATE SEQUENCE, CREATE PROCEDURE TO joe

c.

d.

10.
a. b. c. d.

Which statement about a sequence is true?


A sequence can only be used to create a primary key value One sequence can be used for multiple tables in the same schema Creating a sequence causes sequence numbers are stored in a table A sequence slows down the efficiency of accessing sequence values cached in memory

11.

The MANAGER role should be given the ability to select from insert into and modify existing rows in the STUDENT_GRADES table. Anyone given this MANAGER role should be able to pass those privileges on to others. Which statement accomplishes this?
GRANT select, insert, update ON student_grades TO manager; GRANT select, insert, update ON student_grades TO ROLE manager GRANT select, insert, modify ON student_grades TO manager WITH GRANT OPTION; GRANT select, insert, update ON student_grades TO manager WITH GRANT OPTION

a. b. c. d.

A view was created with the following command: CREATE FORCE VIEW first_vu AS SELECT first_name ||' '|| last_name "Employee Names" FROM employee ORDER BY last_name, first_name; Which clause causes an error?
a. b. c. d. CREATE FORCE VIEW first_vu ORDER BY last_name, first_name FROM employee AS SELECT first_name ||' '|| last_name "Employee Names"

12.

1.
a. b. c. d.

What is the correct use of the Trunc command on a date?


TRUNC=To_Date('09-Jan-02,DD-MON-YY,'YEAR',"Date" from Dual; Select TRUNC(To_Date('09-Jan-02,DD-MON-YY,YEAR')) "DATE" from Dual; Date =TRUNC(To_DATE('09-Jan-02','DD-MON-YY'),'YEAR'),'YEAR)"DATE: from DUAL; SELECT TRUNC(TO_DATE('12-Feb-99','DD-MON-YY'), 'YEAR') "Date " FROM DUAL;

2.
a. b. c. d. e.

Which type of join should be written to perform an outer join of tables A and B that returns all rows from B?
Any outer join A left outer join A cross join A right outer join An inner join

3.
a. b. c. d.

How many join conditions should be there to avoid a Cartesian Join for joining three tables?
1 2 3 None of the above

4.
a. b. c. d.

Top N analysis requires ____________ and ____________.


The use of rowed & Only an inline view a GROUP BY clause & Only an inline view an ORDER BY clause & An inline view and an outer query None of the above

Examine the code given below: 5. SELECT employee_id FROM employees WHERE commission_pct=.5 OR salary > 23000 Which of the following statement is correct with regard to this code?
a. b. c. d. It returns employees who have 50% of the salary greater than $23,000: It returns employees who have 50% commission rate or salary greater than $23,000: It returns employees who have 50% of salary less than $23,000: None of the above

6.

The STUDENT_GRADES table has the following columns:

STUDENT_ID NUMBER (12)

SEMESTER_END DATE

GPA NUMBER (4, 3)

Which of the following statements finds the highest Grade Point Average (GPA) per semester?
a. b. c. d. e. SELECT MAX(gpa) FROM student_grades WHERE gpa IS NOT NULL; SELECT (gpa) FROM student_grades GROUP BY semester_end WHERE gpa IS NOT NULL; SELECT MAX(gpa) FROM student_grades WHERE gpa IS NOT NULL GROUP BY semester_end; SELECT MAX(gpa) GROUP BY semester_end WHERE gpa IS NOT NULL FROM student_grades; SELECT MAX(gpa) FROM student_grades GROUP BY semester_end WHERE gpa IS NOT NULL;

7.
a. b. c. d. e.

Which of the following tasks can be performed by using the TO_CHAR function?
Convert '10'to 10 Convert 10 to '10' Convert 'TEN' to 10 Convert a date to a character expression Convert a character expression to a date

8.
a. b. c. d. e.

Which of the following SELECT statements will get the result 'elloworld' from the string 'HelloWorld'?
SELECT SUBSTR ('HelloWorld',1) FROM dual; SELECT INITCAP(TRIM('HellowWorld', 1,1) FROM dual; SELECT LOWER (SUBSTR ('HellowWorld', 2,1) FROM dual; SELECT LOWER (SUBSTR('HellowWorld', 2,1) FROM dual; SELECT LOWER (TRIM ('H' FROM 'Hello World')) FROM dual;

9.
a. b. c. d.

Where is the GROUP BY clause statement placed in a SELECT statement that includes a WHERE clause?
Immediately after the SELECT clause Before the WHERE clause After the ORDER BY clause After the WHERE clause

10.

Which operators can be used in an outer join condition?

a. b. c. d.

= OR IN AND

11.
a. b. c. d.

Which type of view is implemented as a subquery embedded in the FROM clause of a SELECT statement and is identified by an alias?
Simple Inline Complex Nested

Evaluate the following SQL statement: 12. SELECT ROUND (TRUNC (MOD (1600, 10),-1), 2) FROM dual; What will be displayed?
a. b. c. d. 0 1 0.00 An error statement

SQL Queries Questions


1. The following relations keep track of airline flight information: Flights(flno: integer, from: string, to: string, distance: integer, departs: time, arrives: time, price: integer) Aircraft(aid: integer, aname: string, cruisingrange: integer) Certified(eid: integer, aid: integer) Employees(eid: integer, ename: string, salary: integer) Note that the Employees relation describes pilots and other kinds of employees aswell; every pilot is certified for some aircraft, and only pilots are certified to fly.Write each of the following queries in SQL. a. Find the names of aircraft such that all pilots certified to operate them earn more than $80,000. b. For each pilot who is certified for more than three aircraft, find the eid and the maximum cruisingrange of the aircraft for which she or he is certified. c. Find the names of pilots whose salary is less than the price of the cheapest route from Los Angeles to Honolulu. d. For all aircraft with cruisingrange over 1000 miles, find the name of the aircraft and the average salary of all pilots certified for this aircraft. e. Find the names of pilots certified for some Boeing aircraft. f. Find the aids of all aircraft that can be used on routes from Los Angeles to Chicago. g. Identify the routes that can be piloted by every pilot who makes more than $100,000. h. Print the enames of pilots who can operate planes with cruisingrange greater than 3000 miles but are not certified on any Boeing aircraft. i. A customer wants to travel from Madison to New York with no more than two changes of flight. List the choice of departure times from Madison if the customer wants to arrive in New York by 6 p.m. j. Compute the difference between the average salary of a pilot and the average salary of all employees (including pilots). k. Print the name and salary of every nonpilot whose salary is more than the average salary for pilots. l. Print the names of employees who are certified only on aircrafts with cruising range longer than 1000 miles. m. Print the names of employees who are certified only on aircrafts with cruising range longer than 1000 miles, but on at least two such aircrafts.

n. Print the names of employees who are certified only on aircrafts with cruising range longer than 1000 miles and who are certified on some Boeing aircraft. a)select a.aname,e.ename,e.salary from aircraft a,employees e,certified c where e.eid=c.eid and c.aid=a.aid and e.salary >$80,000. b)select c.eid,max(a.cruisingrange) from certified c,aircraft a where c.aid=a.aid group by c.eid having count(*)>3; c)select e.ename from employees e where e.salary <(select f.price from flights f where f.from =' Los Angeles' and f.to = ' Honolulu'); d)select a.aname,avg(e.salary) from aircraft a,employees e, certified c where e.eid=c.eid and c.aid=a.aid and cruisingrange> 1000 group by a.aname; e)select e.ename from employees e ,certified c,aircraft a where e.eid=c.eid and c.aid=a.aid and a.aname=' Boeing aircraft'; f)select a.aid from aircraft a where a.aid in(f.flno from flights f where f.from=' Los Angeles' and f.to='chicago');

2. Consider the following relational schema. An employee can work in more than one department; the pct_time filed of the Works relation shows the percentage of time that a given employee works in a given department. Emp(eid: integer, ename: string, age: integer, salary: real) Works(eid: integer, did: integer, pct_time: integer) Dept(did: integer, dname: string, budget: real, managerid: integer) Write the following queries in SQL: a. Print the names and ages of each employee who works in both the Hardware department and the Software department. b. For each department with more than 20 full-time-equivalent employees (i.e., where the part-time and full-time employees add up to at least that many fulltime employees), print the did together with the number of employees that work in that department. c. Print the name of each employee whose salary exceeds the budget of all of the departments that he or she works in. d. Find the managerids of managers who manage only departments with budgets greater than $1 million. e. Find the enames of managers who manage the departments with the largest budgets. f. If a manager manages more than one department, he or she controls the sum of all the budgets for those departments. Find the managerids of managers who control more than $5 million. g. Find the managerids of managers who control the largest amounts. h. Find the enames of managers who manage only departments with budgets larger than $1 million, but at least one department with budget less than $5 million. a)Select e.ename,e.age from emp e,works w,dept d where e.eid=w.eid and w.did=d.did and d.dname='Hardware' and d.dname='software'; c)select e.ename from emp e where e.sal > all(select d.budget from dept d,works w where e.eid=w.eid and w.did=d.did); d)select d.managerid,d.dname from

dept d where d.budget>10,00,000; e)select e.ename from emp e where e.eid in(select d.managerid from dept d where d.budget= (select max(d1.budget) from dept1)); f)select managerid ,sum(budget)from dept group by managerid having sum(budget)>500000; h)select e.ename from emp e,dept d where e.eid=d.managerid group by e.eid having (d.budget>1,00,000 )and (d.budget<5,00,000);

S-ar putea să vă placă și