A6-Ting Wei Chien(Willy)

.docx

School

Santa Clara University *

*We aren’t endorsed by this school

Course

443

Subject

Computer Science

Date

Jun 11, 2024

Type

docx

Pages

7

Uploaded by CaptainMorningDonkey44

Report
CS443 -- Assignment 6 Ting Wei Chien Write the queries necessary to obtain the required information. Make sure all columns you return have descriptive column headings. You must show the result of the query. For example, if the query is: Show the office id, the city, and the region Your query should be: select office, city, region from offices; and then you need to show the following on the screen: (snapshot of your result) 1) Return the Minimum and Maximum sales for all offices. select min(sales), max(sales) from offices; 2) Determine how many orders were made in 1989. Return the number of rows that meet this condition. select count(order_date) from orders where order_date like '%89'; 3) How many different titles in the sales reps table.
select count(distinct title) from salesreps; 4) What is the average quota for salesreps in office 21. select avg(quota) from salesreps where rep_office = 21; 5) What is the average sale amount for each sale reps in each office. Null should be ignored select office, avg(salesreps.sales) from offices, salesreps where salesreps.rep_office = offices.office group by office; 6) For each salesrep that has made an order, list the minimum, maximum and average order amount for all their orders. Include only those orders made anytime from 1990- 1999. Omit from the list any salesrep that has only made 1 order in this time frame. Sort the results by Empl_Num. select salesreps.empl_num, min(amount), max(amount), avg(amount) from salesreps, orders where salesreps.empl_num = orders.rep and extract(year from order_date) between 1990 and 1999 group by empl_num having count(order_num) > 1 order by empl_num;
7) Use a sub-query to list the Customer number; Name and Credit Limit of any customers who have exceeded their credit limit (amount > credit limit) on any order. select cust_num,company, credit_limit from customers where credit_limit < any ( select amount from orders where cust = cust_num); 8) Use a subquery and using the “all” keyword to find the customer number, Salesrep id, and CreditLimit of every customer whose CreditLimit is larger than the CreditLimit of all of the customers of sales rep number 109. select cust_num,empl_num, credit_limit from salesreps, customers where cust_rep = empl_num and credit_limit > all ( select credit_limit from customers where cust_rep = 109); 9) Do question 8, still using the subquery but do not use the “all” keyword. select cust_num,empl_num, credit_limit from salesreps, customers where cust_rep = empl_num
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help