0% found this document useful (0 votes)
59 views

Name: Morales, Arjay Christopher D. Assignment #: 6-2

The document contains 20 SQL queries and commands performed on various database tables as part of an Introduction to SQL activity. The queries select, insert, delete, and modify data, calculate values, and order and group results. They also use operators, functions and clauses like BETWEEN, IN, JOIN, GROUP BY, HAVING, ORDER BY and subqueries. The final command creates a new SALES_REP table with modified data types from an existing REP table.

Uploaded by

charles Rodillas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
59 views

Name: Morales, Arjay Christopher D. Assignment #: 6-2

The document contains 20 SQL queries and commands performed on various database tables as part of an Introduction to SQL activity. The queries select, insert, delete, and modify data, calculate values, and order and group results. They also use operators, functions and clauses like BETWEEN, IN, JOIN, GROUP BY, HAVING, ORDER BY and subqueries. The final command creates a new SALES_REP table with modified data types from an existing REP table.

Uploaded by

charles Rodillas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Name Morales, Arjay Christopher D.

Assignment #: 6-2
:
Introduction to SQL Activity
Course Code: NCP 1202 Activity Title:

1. Add the following row to the SALES_REP table: rep number: 25, last name: Lim; first name: Louis;
street: 535 Vincent; city: Grove; state: FL; zip code: 33321; commission: 0.00; and rate: 0.05. Display
the contents of the SALES_REP table.

INSERT INTO SALES_REP VALUES


(25,'Lim','Louis','535 Vincent','Grove','FL',33321,0.00,0.05);

2. Delete the SALES_REP table.

DROP TABLE SALES_REP;

3. List the part number, description, and price for all parts.

SELECT PART_NUM, DESCRIPTION, PRICE


FROM PART;

4. List the names of customers with credit limits of $10,000 or more.

SELECT CUSTOMER_NAME
FROM CUSTOMER
WHERE CREDIT_LIMIT >= 10000;

5. List the order number for each order placed by customer number 608 on 10/23/2010. (Hint: Use the
YYYY-MM-DD' format for date values)

SELECT ORDER_NUM
FROM ORDERS
WHERE CUSTOMER_NUM = '608' AND ORDER_DATE = '2010-10-23';

6. List the number and name of each customer represented by sales rep 35 or sales rep 65.

SELECT CUSTOMER_NUM, CUSTOMER_NAME


FROM CUSTOMER
WHERE REP_NUM = 35;

University of the East - Caloocan Page 1 of 4


College of Engineering – CpE Department
7. List the part number and part description of each part that is not in item class AP.

SELECT PART_NUM, DESCRIPTION


FROM PART
WHERE NOT (CLASS = 'AP');

8. List the part number, description, and number of units on hand for each part that has between 10 and 25
units on hand, including both 10 and 25. (USE THE BETWEEN CLAUSE)

SELECT PART_NUM, DESCRIPTION, ON_HAND


FROM PART
WHERE ON_HAND BETWEEN 10 AND 25

9. List the part number, part description, and on-hand value (units on hand * unit price) of each part in item
class SG. Assign the name ON_HAND_VALUE to the computed column.

SELECT PART_NUM, DESCRIPTION, (ON_HAND * PRICE) AS ON_HAND_VALUE


FROM PART
WHERE CLASS = 'SG';

10. List the part number, part description, and on-hand value for each part who’s on-hand value is at least
$7,500. Assign the name ON_HAND_VALUE to the computed column.

SELECT PART_NUM, DESCRIPTION, (ON_HAND * PRICE) AS


ON_HAND_VALUE
FROM PART
WHERE (ON_HAND * PRICE) >= 7500;

11. Use the IN operator to list the part number and part description of each part in item class AP or SG.

SELECT PART_NUM, DESCRIPTION


FROM PART
WHERE CLASS IN ('AP', 'SG');

12. Find the number and name of each customer whose name begins with the letter “B.”

SELECT CUSTOMER_NUM, CUSTOMER_NAME


FROM CUSTOMER
WHERE CUSTOMER_NAME LIKE 'B%';

University of the East - Caloocan Page 2 of 4


College of Engineering – CpE Department
13. List all details about all parts. Order the output by part number within warehouse. (That is, order the
output by warehouse and then by part number.)

SELECT *
FROM PART
ORDER BY WAREHOUSE, PART_NUM;

14. How many customers have balances that are more than their credit limits?

SELECT COUNT (CUSTOMER_NAME)


FROM CUSTOMER
WHERE BALANCE > CREDIT_LIMIT;

15. Find the total of the balances for all customers represented by sales rep 65 with balances that are less
than their credit limits.

SELECT CUSTOMER_NUM, CUSTOMER_NAME, BALANCE, CREDIT_LIMIT


FROM CUSTOMER
WHERE REP_NUM = 65 AND BALANCE <CREDIT_LIMIT;

16. List the part number, part description, and on-hand value of each part whose number of units on hand is
more than the average number of units on hand for all parts. (Hint: Use a subquery.)

SELECT PART_NUM, DESCRIPTION, (ON_HAND * PRICE) AS ON_HAND_VALUE


FROM PART
WHERE ON_HAND >
(SELECT AVG (ON_HAND)
FROM PART);

17. What is the price of the least expensive part in the database?

SELECT MIN(PRICE)
FROM PART;

18. What is the part number, description, and price of the least expensive part in the database? (Hint: Use a
subquery.)

University of the East - Caloocan Page 3 of 4


College of Engineering – CpE Department
SELECT PART_NUM, DESCRIPTION, PRICE
FROM PART
WHERE PRICE = (SELECT MIN(PRICE)
FROM PART);

19. List the sum of the balances of all customers for each sales rep, but restrict the output to those sales reps
for which the sum is more than $10,000.

SELECT REP_NUM, SUM(BALANCE)


FROM CUSTOMER
GROUP BY REP_NUM
HAVING SUM(BALANCE) > 10000
ORDER BY REP_NUM;

20. Create a table named SALES_REP. The table has the same structure as the REP table except the
LAST_NAME column should use the VARCHAR data type and the COMMISSION and RATE
columns should use the INT data type. Execute the command to describe the layout and characteristics
of the SALES_REP table.

CREATE TABLE SALES_REP


(REP_NUM CHAR(2) PRIMARY KEY,
LAST_NAME VARCHAR(15) NOT NULL,
FIRST_NAME CHAR(15) NOT NULL,
STREET CHAR(15),
CITY CHAR(15),
STATE CHAR(2),
ZIP CHAR(5),
COMMISSION INTEGER,
RATE INTEGER);

University of the East - Caloocan Page 4 of 4


College of Engineering – CpE Department

You might also like