Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

1 SQL Question

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

LAB: WEEK 1

I. Product relational schema:


s_region(id,name)
s_title(title)
s_dept(id,name,region_id)
s_emp(id,last_name,first_name,userid,start_date,comments,manager_id,title,dep
t_id, salary,commission_pct)
s_customer(id,name,phone,address,city,state,country,zip_code,credit_rating,sale
s_rep_id,region_id,comments)
s_product(id,name,short_desc,suggested_whlsl_price,whlsl_units)
s_ord(id,customer_id,date_ordered,date_shipped,sales_rep_id,total,payment_typ
e,order_filled)
s_item(ord_id,item_id,product_id,price,quantity,quantity_shipped)
II. Connect to sys user and create a user:
--Open Sqlplus and connect to sys

>sqlplus / as sysdba

--Create user

Create user c##myuser identified by password;

Grant DBA to c##myuser;

III. Create a Database and generate a ERD diagram


a. Create a DB:
- Connect to c##myuser (use Oracle SQL Developer).
- Run ‘createProductScript.sql’ file to create and add data to the tables.
b. Generate an entity-relationship (ER) diagram using Oracle SQL Developer
Create a diagram for existing database schema or its subset as follows:

1. Click File → Data Modeler → Import → Data Dictionary.

2. Select a DB connection (add one if none).

3. Click Next.

4. Check one or more schema names.

5. Click Next.

6. Check one or more objects to import.


7. Click Next.

8. Click Finish.

The ERD is displayed.

IV. Use SQL Plus or SQL developer to do the following questions:


1. Display the user id for employee 23.
2. Display the first name, last name, and department number of the
employees in departments 10 and 50 in alphabetical order of last name.
Merge the first name and last name together, and title the column
Employees. (Use ‘||’ to merge columns).
3. Display all employees whose last names contain an “s”.
4. Display the user ids and start date of employees hired between May
5,1990 and May 26, 1991. Order the query results by start date
ascending order.
5. Write a query to show the last name and salary of all employees who
are not making between 1000 and 2500 per month.
6. List the last name and salary of employees who earn more than 1350
who are in department 31, 42, or 50. Label the last name column
Employee Name, and label the salary column Monthly Salary.
7. Display the last name and start date of every employee who was hired
in 1991.
8. Display the employee number, last name, and salary increased by 15%
and expressed as a whole number
9. Display the employee last name and title in parentheses for all
employees. The report should look like the output below.
EMPLOYEE
----------------------------------------------------
Biri(Warehouse Manager)
Catchpole(Warehouse Manager)
Chang(Stock Clerk)
Dancs(Stock Clerk)
Dumas(Sales Representative)
10. Display the product name for products that have “ski” in the name.
11. For each employee, calculate the number of months between today and
the date the employee was hired. Order your result by the number of
months employed. Round the number of months up to the closest whole
number. (use the MONTHS_BETWEEN and ROUND function).
12. Display the highest and lowest order totals in the S_ORD. Label the
columns Highest and Lowest, respectively.
13. Display the product name, product number, and quantity ordered of all
items in order number 101. Label the quantity column ORDERED.
14. Display the customer number and the last name of their sales
representative. Order the list by last name.
15. Display the customer number, customer name, and order number of all
customers and their orders. Display the customer number and name,
even if they have not placed an order.
16. Display all employees by last name and employee number along with
their manager’s last name and manager number.
17. Display all customers and the product number and quantities they
ordered for those customers whose order totaled more than 100000.
18. Display the id, full name of all employees with no manager.
19. Alphabetically display all products having a name beginning with Pro.
20. Display all product ids, names and short descriptions (short_desc) for
all descriptions containing the word bicycle.
21. Determine the number of managers without listing them.
22. Display the customer name, phone, and the number of orders for each
customer.
23. Display the employee number, first name, last name, and user name for
all employees with salaries above the average salary.
24. Display the employee number, first name, and last name for all
employees with a salary above the average salary and that work with
any employee with a last name that contains a “t”.
25. Write a query to display the minimum, maximum, and average salary
for each job type ordered alphabetically.

You might also like