1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
rodikova [14]
2 years ago
9

A department store maintains data on customers, products, and purchase records in three tables: customer, product, and purchase.

the store manager wants to know which product is on maximum discount for each category. write a query to print the following fields for each category, ordered by category, ascending: category, product id and discount for the product that has the maximum discount in the category. in the case of multiple products having same maximum discount within a category, print the product with minimum product_id.
Computers and Technology
1 answer:
saw5 [17]2 years ago
8 0
<h3>The maximum discount using SQL</h3>

Product_Id  Product_Name   Category  Price   Discount  Available

    1           P-1            C-5        720     10       1

    2           P-2            C-1        935     17       1

    3           P-3            C-2        588     19       1

    4           P-4            C-4        619     5        0

    5           P-5            C-1        803     16       1

<h3>The Output </h3>

C-1 2 17

C-2 3 19

C-4 4 5

C-5 1 10

The code that would print the fields in SQL for the maximum discount is:

WITH newTable AS (

SELECT

t.Category,

t.Product_Id,

b.Discount as maxDiscount,  

ROW_NUMBER() OVER (

                        PARTITION BY t.Category

                        ORDER BY Product_Id DESC

                  ) AS [ROW NUMBER]

FROM Products t

INNER JOIN

(

 SELECT MAX(Discount) as maxDiscount, Category

 FROM Products

GROUP BY Category

) b ON t.Discount = b.Discount AND t.Category = b.Category)

select Category,Product_Id,maxDiscount from newTable

WHERE newTable.[ROW NUMBER] = 1

Read more about SQL here:

brainly.com/question/25694408

#SPJ1

You might be interested in
What does an operating system do
3241004551 [841]

Answer: An operating system manages and runs all of the hardware and software installed onto the computer.

Explanation:

It performs basic tasks such as file, memory, and process management, handling input and output, and controlling peripheral devices such as disk drives and printers.

7 0
10 months ago
You administer a Microsoft SQL Server database that supports a banking transaction management application. You need to retrieve
dusya [7]

Answer:

A, B

Explanation:

A. selects accountholder's ids and check them with those who don't have cities in BranchMaster table.

B. We can use both <em>NOT IN</em><em> </em> as well as <> operator for comparison so it selects accountholder's ids which are not in all of those account holders who have cities in BranchMaster.

5 0
3 years ago
The quicksort is an example of a divide and conquer algorithm in that it divides the sorting problem into smaller problems by di
ankoles [38]

Answer:

The quicksort pivot is an arbitrary element within the collection that is being sorted.  Using the pivot point, the collection of elements is partitioned into two smaller lists of elements.  Using some logic, the smaller elements are placed left of the pivot point, and larger elements are placed to the right of the pivot point.  Ideally, you would prefer you pivot point to be a median of your dataset to optimize the creation of the two sublists into a balanced state.

Cheers.

8 0
3 years ago
Suppose that the code below is the body of some loop. Given variables x and y write some code that reads a value into the variab
ra1l [238]

Answer:

I will code in JAVA.

import java.util.Scanner;

public class Main {

public static void main(String[] args) {

     float x;

     float y;

     float result;

     Scanner input = new Scanner(System.in);

     while(true){ <em>//this is an infinite loop</em>

       x = input.nextFloat(); <em>//wait the input for x</em>

       y = input.nextFloat(); <em>//wait the input for y</em>

       if(y == 0) {

         continue; <em>//next iteration without print.</em>

       } else{

         result = x/y;

         System.out.print(result); <em>//print the result.</em>

       }

     }

 }

}

Explanation:

To get the numbers, you need to import Scanner class, and use the method nextFloat() to admit floats and integers.

If y is 0 then, executes the continue statement, if not prints the division between x and y.

4 0
3 years ago
Scenario: An organization has an incident response plan that requires reporting incidents after verifying them. For security pur
Ronch [10]
D, gather evidence, it’s obvious he should have reported the problem which as many evidence possibly found, instead decides to reboot the server.
3 0
3 years ago
Other questions:
  • Sometimes data you export from Access needs to be formatted as a text file instead of an Excel file.
    14·1 answer
  • A software engineer is designing a new program. She decides to first define all the classes needed, and how they will interact w
    5·2 answers
  • What two pieces of information would you need in order to measure the masses of stars in an eclipsing binary system?
    9·1 answer
  • HELP PLEASE!!! I do online school, someone is in another state wanting to help me. No not do my work for me but view what I view
    6·1 answer
  • To accomplish a certain task when you would rsther be doing something else is an example of
    9·1 answer
  • Edhesive unit 4 test answers
    15·1 answer
  • ABC IF U HAVE A LEGENDARY PET ON ADOPT ME OR ANYTHING COOL!! &lt;3
    5·2 answers
  • What types of information should have their sources cited to avoid plagiarism? List at least 3
    10·1 answer
  • The objective fuction of linear progrmming should be
    10·1 answer
  • What feature should you enable to prevent the sidhistory attribute from being used to falsely gain administrative privileges in
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!