A6-Ting Wei Chien(Willy)
.docx
keyboard_arrow_up
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
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
Related Questions
You have been told that you need to store the zip code for employees. Add a column to the EMPLOYEE table which will be used to store each employee’s zip code
Update two rows in the EMPLOYEE table and assign a zip code (must have a WHERE clause). (you MAY use 1 or 2 statements)
Write a query that includes each employee's last name, department name (not ID), and salary for each employee whose salary is less than the average for their department
arrow_forward
SQL Server
Please help answer question 5
Please type out the answer because I cannot read the last answer because the handwriting is not very clear. Thank you.
arrow_forward
2
arrow_forward
Sp8.
arrow_forward
Databases
arrow_forward
Write a SELECT statement that returns three columns: EmailAddress, OrderID, and the order total for each customer. To do this, you can group the result set by the EmailAddress and OrderID columns. In addition, you must calculate the order total from the columns in the OrderItems table.
Write a second SELECT statement that uses the first SELECT statement in its FROM clause. The main query should return two columns: the customer�s email address and the largest order for that customer. To do this, you can group the result set by the EmailAddress column.
arrow_forward
7.
SELECT name
FROM instructor
WHERE salary = 90000;
This query can be replaced by which of the following ?
a)
SELECT name
FROM instructor
WHERE salary BETWEEN 90000 AND 100000;
b)
SELECT name
FROM employee
WHERE salary =100000;
c)
SELECT name
FROM employee
WHERE salary BETWEEN 90000 AND 100000;
d)
SELECT name
FROM instructor
WHERE salary BETWEEN 100000 AND 90000;
arrow_forward
WEEK SQL ASSIGNMENT
Complete the following exercise:
Alter your student table adding a new column called enroll_date using the datetime data type.
Populate the new column (enroll_date) with the current date and time.
Using your student table return the student first and last names concatenated with a space and then the enroll_date minus one month. Here is an example of the output:
Name
Date
Jane Smith
2019-05-03 13:14:12
Tom Jones
2020-08-07 05:23:56
Using your student table return the month name for the enroll_date column. For example, if the enroll_date was 11-6-2019 then the month name would be June.
arrow_forward
SQL server
Answer question 5
arrow_forward
473/quizzes/3522244/take
Question 3
15 pts
Prompt:
Develop a query to provide details about customer sales at the end of 2014. You want the output to
include the following attributes in this order: sale ship-to city, customer last name, and sale ship
date. Restrict the query to include sales that were shipped to cities that end in the letter "o" and
were shipped on a date within the last four months of 2014. Sort the query output first by the ship-
to city and next by the customer last name.
SQL Statement (case sensitive, must reflect what was used in SQL Browser to execute the prompt):
SELECT Sale.ShipToCity, Customer.LastName, Sale.ShipDate
FROM Sale JOIN Customer ON
Sale. SalelD
=Customer.
CustID
WHERE
Sale.ShipToCity LIKE
"%o"
AND Sale.ShipDate
BETWEEN
"2014-09-01"
AND "2014-12-31"
ORDER BY Sale.ShipToCity, Customer.LastName;
Query Result Count (enter number only, ex. 12):
Result:
rows
arrow_forward
Q4
arrow_forward
P5
arrow_forward
Q1) Please write. a query statement from emp table to display deptno 10’s empno, ename, sal, and a new_sal which is increase by 15% from the original sal (round the new_sal value to a whole number). Label the column headings to EMPNO, ENAME, SAL, and NEW_SAL. The result should be like below:
[ image below - scr_question1.png ]
Q2) Please write .a query statement from emp table to display deptno 30’s empno, ename, sal, comm, and total_income which is a new column of the amount of sal + comm. Label the column heading to EMPNO, ENAME, SAL, COMM, TOTAL_INCOME. The result should be like below:
[ image below - src_question2.png ]
-------------------------------------------------------------------------
Here is the material needed to answer those questions:
Material:
https://drive.google.com/file/d/14OwWDIybjAIeuHCO7McupV08gJs9nB-8/view?usp=sharing
https://drive.google.com/file/d/1npRH8JoJ6GYBzPU3iNjLXluvCyhr2tMu/view?usp=sharing
arrow_forward
SEE MORE QUESTIONS
Recommended textbooks for you
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning
A Guide to SQL
Computer Science
ISBN:9781111527273
Author:Philip J. Pratt
Publisher:Course Technology Ptr
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:9781337508841
Author:Carey
Publisher:Cengage
Related Questions
- You have been told that you need to store the zip code for employees. Add a column to the EMPLOYEE table which will be used to store each employee’s zip code Update two rows in the EMPLOYEE table and assign a zip code (must have a WHERE clause). (you MAY use 1 or 2 statements) Write a query that includes each employee's last name, department name (not ID), and salary for each employee whose salary is less than the average for their departmentarrow_forwardSQL Server Please help answer question 5 Please type out the answer because I cannot read the last answer because the handwriting is not very clear. Thank you.arrow_forward2arrow_forward
- Sp8.arrow_forwardDatabasesarrow_forwardWrite a SELECT statement that returns three columns: EmailAddress, OrderID, and the order total for each customer. To do this, you can group the result set by the EmailAddress and OrderID columns. In addition, you must calculate the order total from the columns in the OrderItems table. Write a second SELECT statement that uses the first SELECT statement in its FROM clause. The main query should return two columns: the customer�s email address and the largest order for that customer. To do this, you can group the result set by the EmailAddress column.arrow_forward
- 7. SELECT name FROM instructor WHERE salary = 90000; This query can be replaced by which of the following ? a) SELECT name FROM instructor WHERE salary BETWEEN 90000 AND 100000; b) SELECT name FROM employee WHERE salary =100000; c) SELECT name FROM employee WHERE salary BETWEEN 90000 AND 100000; d) SELECT name FROM instructor WHERE salary BETWEEN 100000 AND 90000;arrow_forwardWEEK SQL ASSIGNMENT Complete the following exercise: Alter your student table adding a new column called enroll_date using the datetime data type. Populate the new column (enroll_date) with the current date and time. Using your student table return the student first and last names concatenated with a space and then the enroll_date minus one month. Here is an example of the output: Name Date Jane Smith 2019-05-03 13:14:12 Tom Jones 2020-08-07 05:23:56 Using your student table return the month name for the enroll_date column. For example, if the enroll_date was 11-6-2019 then the month name would be June.arrow_forwardSQL server Answer question 5arrow_forward
- 473/quizzes/3522244/take Question 3 15 pts Prompt: Develop a query to provide details about customer sales at the end of 2014. You want the output to include the following attributes in this order: sale ship-to city, customer last name, and sale ship date. Restrict the query to include sales that were shipped to cities that end in the letter "o" and were shipped on a date within the last four months of 2014. Sort the query output first by the ship- to city and next by the customer last name. SQL Statement (case sensitive, must reflect what was used in SQL Browser to execute the prompt): SELECT Sale.ShipToCity, Customer.LastName, Sale.ShipDate FROM Sale JOIN Customer ON Sale. SalelD =Customer. CustID WHERE Sale.ShipToCity LIKE "%o" AND Sale.ShipDate BETWEEN "2014-09-01" AND "2014-12-31" ORDER BY Sale.ShipToCity, Customer.LastName; Query Result Count (enter number only, ex. 12): Result: rowsarrow_forwardQ4arrow_forwardP5arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Programming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage LearningA Guide to SQLComputer ScienceISBN:9781111527273Author:Philip J. PrattPublisher:Course Technology Ptr
- Np Ms Office 365/Excel 2016 I NtermedComputer ScienceISBN:9781337508841Author:CareyPublisher:Cengage
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning
A Guide to SQL
Computer Science
ISBN:9781111527273
Author:Philip J. Pratt
Publisher:Course Technology Ptr
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:9781337508841
Author:Carey
Publisher:Cengage