Question

1. Write a SELECT statement to count SKUs for each department, i.e., a table of two...

1. Write a SELECT statement to count SKUs for each department, i.e., a table of two columns, departments and their SKU counts.

use cape_codd;
select department, count(*)
from sku_data
group by department
;

2. List buyers who is responsible for at least two SKUs, in three columns, department, buyer, sku count. Sort buyers by their department names in ascending order.

select department, buyer, count(sku)
from sku_data
group by buyer
;

3. Write a SQL statement which returns all the orders. For each order, display OrderNumber and the total SKUs in the order. (Hint: there are three order numbers: 1000,2000,3000)


select ordernumber, count(sku)
from order_item
where ordernumber
group by ordernumber
;

4. Write a SQL Join to retrieve total sales for the department "Water Sports". Use explicit JOIN ON syntax. (No credit if you use implicit syntax)

The expected result will be a table of two columns and one row:

department sum(extendedprice)

Water Sports 750

select department, sum(ExtendedPrice)
from order_item join sku_data
;

Homework Answers

Answer #1

1. First question states that
Write a SELECT statement to count SKUs for each department, i.e., a table of two columns, departments and their SKU counts.

so that means we need to show each department with sku numbers in it.

so to form a query we need to select it from the table sku_datafrom which we need to select the nuber of skus in each departments

so if we think logically then we need to form a section where each department with sku counts

generally if we group the departnames and then take the count of each sku in it, it would be done easily

so to group each deparment in sql we have group by section

if you think it logially how db server works that first from table then group by the column then select the columns. but syntactically speeking :-

the query would look like:
use cape_codd;// use the dattabase to run a query on the database table
select department, count(*) as 'sku count' // selecting the department and number of columns associated with the department
from sku_data // from table
group by department // group by with department so that we can have number of columns in which the depart name are same

2.  List buyers who is responsible for at least two SKUs, in three columns, department, buyer, sku count. Sort buyers by their department names in ascending order.

there are multiple problems in it.

so first is listing buyers with sku count
for that we use group by

second is at least two sku counts:

in order to do that in addition to group by we can use having

next arrange it with department names in ascending order
for this we can use order by

so if we form a query then
select department, buyer, count(sku)
from sku_data
group by buyer
having count(sku)>=2
order by department ASC;

3rd Question: Write a SQL statement which returns all the orders. For each order, display OrderNumber and the total SKUs in the order. (Hint: there are three order numbers: 1000,2000,3000)

here also we need to show order numbers with sku counts also that means here also we can group by order numbers for sku count which is same as first question

select ordernumber, count(sku)
from order_item
group by ordernumber

4. Write a SQL Join to retrieve total sales for the department "Water Sports".

here we need to find the total sales for a single specific department
this question is also also formed with multiple question
1. we need to find total number of records in the sales table for department "Water Sports"
So, here as sku_data has department but the sales record is in order_item table so we need to join two tables to find out the number of records associated with it and there is only one column(sku) which is common in both the tables so we will use that column to join both the tables

2. total sales record
so that means we need to perform a sum operation orver the price coumn of department  "Water Sports"

so if we form the query, it would look like below


select department, sum(ExtendedPrice)
from order_item inner join sku_data on order_item.sku=sku_data.sku
where order_item.department='Water Sports';

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a SQL statement which joins the parts table with the supplier table and lists the...
Write a SQL statement which joins the parts table with the supplier table and lists the part_name, supplier_name for all parts in the part table. The supplier_id column in the suppliers table is the primary key in the suppliers table, and this key has been exported to the parts table where it is a foreign key. You should use an inner join for this query. Write a SQL statement which joins the parts table with the suppliers table and lists...
Write a SELECT statement that returns one row for each general ledger account number that contains...
Write a SELECT statement that returns one row for each general ledger account number that contains three columns: The account_description column from the General_Ledger_Accounts table The count of the items in the Invoice_Line_Items table that have the same account_number. The sum of the line_item_amount columns in the Invoice_Line_Items table that have the same account_number Return only those rows where the count of line items is greater than 1. This should return 10 rows. Group the result set by the account_description...
Class-In Assignment 3: Chapters 4&5 How to retrieve data from two or more tables Exercises 1....
Class-In Assignment 3: Chapters 4&5 How to retrieve data from two or more tables Exercises 1. Write a SELECT statement that returns all columns from the Vendors table inner-joined with all columns from the Invoices table. 2. Write a SELECT statement that returns four columns: vendor_name vendor_name from the Vendors table invoice_number invoice_number from the Invoices table invoice_date invoice_date from the Invoices table balance_due invoice_total minus payment_total minus credit_total from the Invoices table The result set should have one row...
Lab 5 Queries with Multiple Tables In this lab, we do queries more than one table....
Lab 5 Queries with Multiple Tables In this lab, we do queries more than one table. SQL provides two different techniques for querying data from multiple tables: • The SQL subquery • The SQL join As you will learn, although both work with multiple tables, they are used for slightly different purposes. We used WMCRM database which is what we created in Lab 4. Here is the summary of the database schema (where schema is used in its meaning of...
1. Complete below SQL statement to find count of records from Customers table. SELECT Country, State,...
1. Complete below SQL statement to find count of records from Customers table. SELECT Country, State, City, Count(*) AS Count FROM Customers 2. Add FK on child_table (column1) refrencing from parent_table (column1). ALTER TABLE child_table
Write a SELECT statement that uses aggregate window functions to calculate the order total for each...
Write a SELECT statement that uses aggregate window functions to calculate the order total for each musician and the order total for each musician by date. Return these columns: The musician_id column from the Orders table The order_date column from the Orders table The total amount for each order item in the Order_Items table The sum of the order totals for each musician The sum of the order totals for each musician by date (Hint: You can create a peer...
1.Write a SELECT statement that returns "Representative full name" from sales_rep table. Format "Representative full name"...
1.Write a SELECT statement that returns "Representative full name" from sales_rep table. Format "Representative full name" column with the rep_first_name column , a comma, a space and the rep_last name. Return only the sales representatives whose last name starts with "Mar" 2. Write a SELECT statement that  joins the sales_rep table to the sales_totals table using JOIN clause and returns these columns : "Representative Last name" : rep_last_name from sales_rep table " Year of sales " : sales_year column of sales_totals...
EMPLOYEE Field Name EMP_ID EMP_LNAME EMP_MI EMP_FNAME EMP_SEX EMP_AGE EMP_SALARY EMP_HIREDATE DEPT_CODE Table: DEPARTMENT DEPT_CODE BIOL...
EMPLOYEE Field Name EMP_ID EMP_LNAME EMP_MI EMP_FNAME EMP_SEX EMP_AGE EMP_SALARY EMP_HIREDATE DEPT_CODE Table: DEPARTMENT DEPT_CODE BIOL CPTR HIST MATH RELB Data Type Text Text Text Text Text Number Currency Date/Time Text DEPT_TITLE Biology Computer Science History Mathematics Religion    Field Name DEPT_CODE DEPT_TITLE Data Type Text Text INSTRUCTIONS Use SQL commands to create the tables and enter the data shown above using MS Access. Write the following SQL statement given below: 1. 2. 3. 4. 5. 6. 7. 8. 9....
Write a SELECT statement that returns "Representative full name" from sales_rep table. Format "Representative full name"...
Write a SELECT statement that returns "Representative full name" from sales_rep table. Format "Representative full name" column with the rep_first_name column , a comma, a space and the rep_last name. Return only the sales representatives whose last name starts with "Mar" Write a SELECT statement that joins the sales_rep table to the sales_totals table using JOIN clause and returns these columns : "Representative Last name" : rep_last_name from sales_rep table " Year of sales " : sales_year column of sales_totals...
in mysql 3. Write a SELECT statement that returns one row for each customer that has...
in mysql 3. Write a SELECT statement that returns one row for each customer that has orders with these columns:   The email_address column from the Customers table   The sum of the item price in the Order_Items table multiplied by the   quantity in the Order_Items table   The sum of the discount amount column in the Order_Items table   multiplied by the quantity in the Order_Items table   Sort the result set in descending sequence by the item price total for each customer.  
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT