Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
179 views16 pages

Prog 3114 Week1 10 - Compress

The document provides examples of SQL statements and their answers. It contains over 30 examples of SQL queries and the correct answer formatted in a two column table. The answers are highlighted in yellow for correct and grey for incorrect to aid in learning. The purpose is to help students learn and avoid common mistakes by reviewing the examples and answers.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
179 views16 pages

Prog 3114 Week1 10 - Compress

The document provides examples of SQL statements and their answers. It contains over 30 examples of SQL queries and the correct answer formatted in a two column table. The answers are highlighted in yellow for correct and grey for incorrect to aid in learning. The purpose is to help students learn and avoid common mistakes by reviewing the examples and answers.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

PROG 3114.

WEEK 1-10  SELECT


LAST_DAY(hire_date),
I want to sleep lol.
hire_date FROM employees;
Yo, ez Rein. I
compiled the correct
and wrong answers List all the employee_id of all
based on my attempts. employees whose salary is 5000
This docu has a 99% and below and belong to
accuracy (Im not sure if I have department 60 or 100.
typos tho). I placed the wrong
 SELECT employee_id,salary,
answers so you won’t repeat the
department_id FROM
same mistake I did. I also used
employees WHERE salary <
the 2 column format for easy
5000 AND department_id IN
splitscreen. Sorry for the dupes,
(60,100)
NOT ALL ANSWERS ARE IN HERE.

NOTE: ALL YELLOW ANSWERS ARE


MARKED AS CORRECT, GREY ONES ARE Which of the following SELECT
WRONG. statement is the correct PL/SQL
that will display eliminate the
Correct
duplicate rows for column class
Display employee's name and id and warehouse.
whose firstname starts with
 SELECT DISTINCT CLASS,
letter D and job id is SA_REP.
WAREHOUSE FROM PARTS;
Sort the output by department.

 SELECT employee_id,
first_name, last_name Display part number description
FROM employees WHERE and warehouse number whose part
first_name LIKE 'D%' and number starts with letter K.
job_id = 'IT_PROG' ORDER
 SELECT partnum,
BY department_id
description, warehouse
FROM parts WHERE partnum
LIKE 'K%';
Display the first 5 letter in
the surname of all the employees
whose firstname starts with
SQL stands for
letter 'D'
 Structured Query Language
 SELECT
SUBSTR(last_name,1,5),
first_name FROM employees
WHERE Create an SQL command to display
SUBSTR(first_name,1,1) = the name of the parts, warehouse
'D' number, price and the available
stock on hand whose price is
below 500. Arrange the list by
warehouse number and by class.
Display the last day of the
month and the hiring date when  SELECT partnum,
the employees are hired in the description, warehouse,
company. onhand, price FROM parts
WHERE price < 500 ORDER
BY warehouse, class;
Display all the records sorted
by price from most expensive to
Which of the following SELECT
the cheapest parts.
statement is the correct PL/SQL
that will display all rows and  SELECT * FROM parts ORDER
columns? BY price DESC

 SELECT * FROM PARTS;


Which of the following is the
correct report that will display
Display the name, jobs id and
the CLASS from table PARTS.
salary of the all the employees
whose department id is 100 and  SELECT CLASS FROM PARTS;
salary is below 8000. Arrange
the output by salary in
ascending order. Which of the following SELECT
statement is the correctreport
 SELECT first_name,
the will merge the column CLASS
last_name, salary FROM
and PRICE rename the COLUMN as
employees WHERE
"CLASS PRICE".
department_id = 100 AND
salary < 8000 ORDER BY  SELECT (CLASS||PRICE) AS
salary "CLASS PRICE" FROM PARTS;

Which of the following is an Command use to display table


Oracle Proprietary Commands structure
 SQL *Plus  DESCRIBE

Display all employees id and Using CREATE SQL Command, you


remainder of the his/her salary can add new records in the table.
after it is divided by 3,000 for
 False
all employees with the job id of
IT_PROG.
Display the first 3 letter in
 SELECT employee_id,
the first name of all the
job_id, salary,
employees.
MOD(salary, 3000) FROM
employees WHERE job_id =  SELECT
'IT_PROG' SUBSTR(first_name,1,3)
FROM employees;

Which of the following SQL


commands will display all stocks Display all employees whose job
whose class is HW or AP. id contains the word 'ACCOUNT'.
 SELECT * FROM parts WHERE  SELECT * FROM EMPLOYEES
IN class ('HW', 'AP'); WHERE job_id LIKE
'%ACCOUNT%';

Display all the employee's id


and salary whose annual salary
is from 100,000 to 200,000. Which of the following SELECT
Arrange the output by salary in statement is the correctreport
descending order. that will combine the column
PARTNUM and DESCRIPTION put a
 SELECT employee_id,
literal character string
salary FROM employees
"belongs to" in between the two
WHERE salary *12 >=
columns then rename the column
100000 AND salary *12 <=
as "NUMBER TITLE". Note put
200000 ORDER BY salary
space before and after the
desc
character literal string to
avoid no spaces in the report.

Display the montly salary of  SELECT (PARTNUM||' THAT


every employee. Round the salary BELONGS TO
in 2 decimal places. '||DESCRIPTION) AS
"NUMBER TITLE" FROM
 SELECT
PARTS;
ROUND( (salary/12),2 )
FROM employees;
Using Data Manipulation Language,
you can ADD columns in the table.
You can relate data to multiple
tables using a foreign key.  False

 True The two development environments


of Oracle are _______________
and ______________.
Every employee will get a bonus
 Oracle SQL Developer; SQL
of 150% of his/her current
salary. Display the employee id, command line
salary and the bonus of every
employee. Label the computed
bonus with Bonus Which of the following SQL
commands will display all the
 SELECT employee_id, stocks on hand from 10 to 30?
salary, salary * 1.5 AS
Bonus FROM employees  SELECT * FROM parts WHERE
onhand BETWEEN 10 AND 30;

Display the employee id, number


of years and the hiring date of Which of the following SQL
every employee in the company. command will display all records
with class code of AP?
 SELECT employee_id,
hire_date, ROUND((SYSDATE  SELECT * FROM parts WHERE
- hire_date) /365,0) FROM class = ‘AP’;
employees;

Ronnie is the stockman in the


Which of the following is a Data warehouse of ATR Corporation.
Definition Language? The General Manager wants to
know the parts whose price is
 DROP above 10000 and above. Which of
the following SQL command that
Ronnie will run to generate the below 500. Arrange the list by
list. warehouse number and by class.
 SELECT * FROM parts WHERE  SELECT partnum,
price >= 10000; description, warehouse,
onhand, price FROM parts
WHERE price < 500 ORDER
Command use to display table BY warehouse, class;
structure

 DESCRIBE
Display the first 3 letter in
the first name of all the
employees.
Display the total number of
characters of the last name of  SELECT
all the employees. SUBSTR(first_name,1,3)
FROM employees;
 SELECT LENGTH(last_name)
FROM employees;
Which of the following SELECT
statement is the correct PL/SQL
Which of the following SELECT
that willcreate a report that
statement is the correct PL/SQL
will add 10% increase in PRICE?
that willcreate a report
List only the column DESCRIPTION,
specifying only the column PRICE,
CLASS and PRICE.
ONHAND and DESCRIPTION?
 SELECT PRICE*0.10,
 SELECT PRICE, ONHAND, DESCRIPTION, CLASS FROM
DESCRIPTION FROM PARTS;
PARTS;

Display all the records whose Display the employee id, number
stock is below 20 and in
of years and the hiring date of
warehouse number 3.
every employee in the company.
 SELECT * FROM parts WHERE
 SELECT employee_id,
onhand< 20 AND warehouse
hire_date, ROUND((SYSDATE
= 3;
- hire_date) /365,0) FROM
ANSI SQL commands cannot be employees;
abbreviated.

 True
Display all employees id and
remainder of the his/her salary
after it is divided by 3,000 for
Which of the following is a Data all employees with the job id of
Definition Language? IT_PROG.
 DROP
 SELECT employee_id,
job_id, salary,
MOD(salary, 3000) FROM
Create an SQL command to display employees WHERE job_id =
the name of the parts, warehouse 'IT_PROG'
number, price and the available
stock on hand whose price is
Which of the following SELECT Display the last day of the
statement is the correct PL/SQL month and the hiring date when
that willcreate a report the employees are hired in the
specifying only the column PRICE, company.
ONHAND and DESCRIPTION?
 SELECT
 SELECT PRICE, ONHAND, LAST_DAY(hire_date),
DESCRIPTION FROM PARTS; hire_date FROM employees;

Which of the following SQL Display all employees whose job


commands will display all the id contains the word 'ACCOUNT'.
stocks on hand from 10 to 30?
 SELECT * FROM EMPLOYEES
 SELECT * FROM parts WHERE WHERE job_id LIKE
onhand BETWEEN 10 AND 30; '%ACCOUNT%';

Display employee's name and id You want to display the


whose firstname starts with employee’s last name whose
letter D and job id is SA_REP. salary is below 10,000 and
Sort the output by department. whose lastname starts with
 SELECT employee_id,
letter K.
first_name, last_name
Which SQL statement give the
FROM employees WHERE
first_name LIKE 'D%' and
required output format of the
salary?
job_id = 'IT_PROG' ORDER
BY department_id
 SELECT last_name,
TO_CHAR(salary,
'$999,999.99') AS
Which of the following SELECT "MONTHLY SALARY" FROM
statement is the correct PL/SQL employees WHERE salary <
that will display eliminate the 10000WHERE last_name LIKE
duplicate rows for column class ‘K%’
and warehouse.

 SELECT DISTINCT CLASS,


WAREHOUSE FROM PARTS; What will be the output of the
following SQL?

Display the total number of SELECT * FROM parts WHERE


characters of the last name of (warehouse = 1 or warehouse =
all the employees. 2) AND class IN ('HW', 'AP')
AND (price > 200 AND price <
 SELECT LENGTH(last_name) 500);
FROM employees;
 2 rows returned
The following are capabilities
of SQL SELECT
You want to display the
 Projection, Selection, employee's last name hired
Join records from year 2000 to 2002.
Which SQL statement give the Ms. Ella what to generate the
required output? average salary of all
employees whose job function
 SELECT last_name, is IT_PROG.
hire_date FROM employees
WHERE hire_date>= Which of the following SQL
TO_DATE('01-Jan-2000', command will produce the
'DD-Mon-RR') AND output.
hire_date<= TO_DATE('31-
Dec-2002', 'DD-Mon-RR')  SELECT AVG(salary) FROM
employees WHERE job_id =
'IT_PROG';
Which of the following SQL
command will display all records
with part number contains the
number 9?
John want to know how many
part items are there in
 SELECT * from parts WHERE warehouse number 3.
partnum LIKE '%9%'
What SQL command he need to
run?
John want to know how many
employees receiving salary below  SELECT COUNT(*) FROM
10,000. What SQL command he need parts WHERE warehouse =
to run? 3;

 SELECT COUNT(*) FROM


employees WHERE salary <
You want to display the
10000;
employee's last name whose
salary is below 10,000.

You want to display the Which SQL statement give the


employee's id and formatted required output format of the
date hired as shown below. salary?

Which SQL statement give the  SELECT last_name,


required output? TO_CHAR(salary,
'$999,999.99') AS
 SELECT employee_id, "MONTHLY SALARY" FROM
TO_CHAR(hire_date, employees WHERE salary <
'fmMonth DD, YYYY') AS 10000
"Hired Date" FROM
employees;
There was 10% price increase
in the all the parts in
Aldrin wants to know the
warehouse number 3. The Store
outstanding total balance on
Manager asked the Database
hand on every class per
Administrator to generate a
warehouse.
report showing the part number,
 SELECT warehouse, class, the old and new price.
sum(onhand) FROM parts
GROUP BY warehouse, class Which of the following SQL
statement would satisfy the
requirement of the Store
Manager.
You want to display the
 SELECT partnum, price, employee's last name and date
price * 1.1 FROM parts hired in year 2002 whose
WHERE warehouse = 3 salary is above 5000.

Which SQL statement give the


required output?
Display the warehouse number,
class, highest price & lowest  SELECT last_name,
price, total on hand balance hire_date FROM employees
whose class is AP. WHERE hire_date >=
TO_DATE('01-Jan-2002',
Sort the output by warehouse 'DD-Mon-RR') AND
number. hire_date <= TO_DATE('31-
Dec-2002', 'DD-Mon-RR')
 SELECT warehouse, class,
AND salary > 5000;
MAX(price), MIN(PRICE),
sum(onhand)
FROM parts
Which of the following SQL
WHERE class = 'AP'
command will display the summary
GROUP BY warehouse, class
table showing the total quantity
ORDER BY warehouse;
on hand per class.
 SELECT class, sum(onhand)
Display a summary table of the AS "QTY ON HAND" FROM
total quantity on hand above 50 parts GROUP BY class
very class per warehouse

 SELECT warehouse, class,


sum(onhand) FROM parts
You want to display the last
GROUP BY warehouse,class name and the year when an
HAVING SUM(ONHAND) > 50 employee was hired whose job
id is IT_PROG.

What is the SQL command to


Which SQL statement give the
required output?
display the date of the first
employee that was hired?
 SELECT last_name,
 SELECT MIN(hire_date) TO_CHAR(hire_date,'YYYY')
FROM employees; FROM employees WHERE
job_id = ‘IT_PROG’;

You want to display the


employee id and the year when What will be the output of the
an employee was hired. SQL command?
SELECT SUM(onhand) FROM PARTS
Which SQL statement give the where class = 'HW' OR class =
required output? 'AP' AND warehouse = 1;
 137
 SELECT employee_id,
TO_CHAR(hire_date,'YYYY')
FROM employees;
The General Manager request to Remove the Shareholder Services
the Database Administrator to department in the department
generate the total salary per table
month of every department in the
 DELETE FROM departments
company.
WHERE department_name =
 SELECT department_id, ‘Shareholder Services’
SUM(salary) FROM
employees GROUP BY
department_id Remove all Manager positions in
the department table.

 DELETE FROM jobs WHERE


You want to display the
job_title LIKE
employee id and the month an
'%Manager%';
employee was hired.

Which SQL statement give the


Diana Lorentz was transferred to
required output?
Administration department. Using
 SELECT employee_id, the employees and department
hire_date, table information update the
TO_CHAR(hire_date,'Month' profile of employee.
) AS "Hired Month" FROM  UPDATE employees SET
employees; manager_id = 200,
Aldrin wants to know the highest department_id = 10 WHERE
salary in every department. last_name = 'Lorentz' AND
Which of the following SQL first_name = 'Diana';
command will display the
required output?
Add a 500 pesos increase in
 SELECT department_id, salary of all employees who have
MAX(salary) FROM rendered services 10 years and
employees GROUP BY above.
department_id
 UPDATE employees SET
salary = salary + 500
where
You want to display the
TO_CHAR(sysdate,'YYYY') -
employee id, date hired of all
TO_CHAR(hire_date,'YYYY')
employees whose hired date is
>= 10
September.

Which SQL statement give the


required output? Given the SQL command
SELECT * FROM employees JOIN
 SELECT employee_id, departments USING
hire_date, (department_id)
TO_CHAR(hire_date, Which of the following describes
'Month') AS "Hired Month" the SQL command?
FROM employees WHERE  Joined table from the
TO_CHAR(hire_date, 'MON') employees and department
= 'SEP' table

You might also like