General
Enthusiast

## aggregate functions to get the following output

input :

store_id  product_name  sale

123          abc                 200

123          xyz                 800

123          ghi                  -400

123          def                  -700

123          lop                  1000

required a new output column whose total sum will be same as sal column i.e 900

negative value will be removed using the highest value in sale .

for eg:  1000 + ( -700) =300

300 + (-400) = -100

-100+800  =  700

so output column required is :

store_id  product_name  sale   desired_output_column

123          abc                 200        200

123          xyz                 800        700

123          ghi                  -400         0

123          def                  -700         0

123          lop                  1000         0

please help to get the result set as shown above.

2 REPLIES
Enthusiast

## Re: aggregate functions to get the following output

hello,

can someone please look into the above query?

Senior Apprentice

## Re: aggregate functions to get the following output

Why are zeroes returned for the last three rows and why is the result in the first row 200?

How do you determine the order of rows for thos calculation?