Question

Write SELECT statement that returns the "Representative ID" and their highest sales total of that sales...

Write SELECT statement that returns the "Representative ID" and their highest sales total of that sales representative, grouped by the " Representative ID" .

Representative ID    : rep_id column of rep_totals table

"Highest sales of Representative " : maximum sales_total of that representative.

Return only the rep_id whose highest sales_total is greater than 900000

Expected Output:

Representative ID Highest sales of representative

1 1274856.38

2 978465.99

3 1132744.56

Homework Answers

Answer #1

Select rep_id AS “Representative ID Highest sales of representative” from rep_totals GROUP BY rep_id HAVING SUM(sales_total)>5000;

The above-mentioned command has to be written to fetch the expected output as given in the question.

GROUP BY CLAUSE:

  • In this question, group by clause is used with the having clause.
  • Basically group by clause is used to group a set of rows into a pack of summary rows by returning the value of that particular field/column.
  • It is used to return one row specified for each group.
  • In conclusion, group by clause decreases the number of rows in the output.
  • Many aggregate functions like sum, Max, count, average and min can be used in groups by syntax but for further filtration of the group specified by GROUP BY clause HAVING Clause is used.

HAVING CLAUSE:

  • It is basically used in select statements for further filtration of a group of rows done by Group by clause.
  • It is mostly used after a group by clause based on a specified condition.
  • Having Clause is similar to where clause but the only difference between having and where Clause is:
  • WHERE filter the data and filtration is done on individual rows.
  • Although GROUP BY clause filters the data and filtration is done on the group of rows as aggregated by Group by clause.
  • Many aggregate functions like Sum, Max, min and count can be used in having clauses.

In this question firstly rep_id has to be mentioned as in the name of Representative ID Highest sales of representative.

Representative id has to be fetched from our present total sales table named as rep_totals.

  • In this command firstly group by clause grouping the set of rows based on representative ID column.
  • Then Having Clause is applied with sum function.
  • Sum function has to be applied to add all the sales of a particular representative.
  • Now, Having function applied on the set of rows to fetch the value of total sale (as already done by SUM function) done by a particular representative who is having their individual total sales greater than 900000.
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
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...
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...
Write an update statement modifies the sales_total column of sales_totals table. Modify the sales_total as "2345.56"...
Write an update statement modifies the sales_total column of sales_totals table. Modify the sales_total as "2345.56" for the representative with id 4 for the year 2017 After execution of your query, data of sales_Totals table should look as shown below : rep_id sales_year sales_total 1 2016 1274856.38 1 2017 923746.85 1 2018 998337.46 2 2016 978465.99 2 2017 974853.81 2 2018 887695.75 3 2016 1032875.48 3 2017 1132744.56 4 2017 2345.56 4 2018 72443.37 5 2017 422847.86 5 2018 45182.44...
In SQL working with data types 1. Write a SELECT statement that returns these columns from...
In SQL working with data types 1. Write a SELECT statement that returns these columns from the Instructors table: a. The monthly salary (the AnnualSalary column divided by 12) b. A column that uses the CAST function to return the monthly salary with 1 digit to the right of the decimal point c. A column that uses the CONVERT function to return the monthly salary as an integer d. A column that uses the CAST function to return the monthly...
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...
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.  
Given the following two related tables, write the SQL SELECT statement to solve the following queries...
Given the following two related tables, write the SQL SELECT statement to solve the following queries about developers (Dev) and programs (Prog). The id column in Dev and Prog is the relation between the two tables. Dev(id, name, dept, salary) Prog(id, title, language, lines, size); 1. List name of Devs who have written more than 1000 line programs 2. List title of all programs written in C++ language 3. List name of all developers who have written C++ programs
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....
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...
implement in Oracle Sql please 5) Write a SELECT statement that answers this question: Which products...
implement in Oracle Sql please 5) Write a SELECT statement that answers this question: Which products have a list price that’s greater than the average list price for all products? Return the product_name and list_price columns for each product. Sort the results by the list_price column in descending sequence.
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT