Have the help of the clause

Oracle version 8i (we will migrate the db to 12 c in the next few months)

This is defination and data table:

create table sales

(

prod_id varchar2 (10),

PROD_NAME varchar2 (30),

salesman_id varchar2 (10),

salesman_name varchar2 (30),

commission_per varchar2 (10),

commission_amt varchar2 (10)

)

/

Insert in the value of sales ('prd1',' 1 ', ' 1', 'sm1' ", '10');

Insert in the value of sales ('prd1',' 1 ', ' 2', 'sm2' ", '10');

Insert in the value of sales ('prd1',' 1 ', ' 3', 'sm3' ", '10');

Insert in the value of sales ('2 ', 'prd2', '1', 'sm1', '10.00' ");

Insert in the value of sales ('2 ', 'prd2', '2', 'sm2', '10.00' ");

Insert in the value of sales ('3 ', 'prd3', '2', 'sm2', '10.00' ");

Insert in the value of sales ('3 ', 'prd3', '1', 'sm1', '15,00' ");

Insert in the value of sales ('3 ', 'prd3', '3', 'sm3', '10.00' ");

Insert in the value of sales ('4 ', 'prd4', '1', 'sm1', '10.00' ");

Insert in the value of sales ('4', 'prd4', ' 2 ', 'sm2' ", '15');

Insert in the value of sales ('5', 'prd5', ' 1 ', 'sm1' ", '15');

Insert in the value of sales ('6', 'prd6', ' 1 ', 'sm1' ", '15');

Insert in the value of sales ('6', 'prd6', ' 2 ', 'sm2' ", '15');

Insert in the value of sales ('6', 'prd6', ' 3 ',' sm3 ', 15', ");

Insert in the value of sales ('6', 'prd6', ' 4 ',' sm4 ', 15', ");

Insert in the value of sales ('7', 'prd7', ' 1 ', 'sm1' ", '15');

Insert in the value of sales ('7', 'prd7', ' 2 ', 'sm2' ", '15');

Insert in the value of sales ('7', 'prd7', ' 3 ', 'sm3' ", '15');

Insert in the value of sales ('7', 'prd7', ' 4 ', 'sm4' ", '15');

Insert in the value of sales ('7', 'prd7', ' 7 ', 'sm7' ", '15');

Insert in the value of sales ('7', 'prd7', ' 5 ', 'sm1' ", '10');

Insert in the value of sales ('7', 'prd7', ' 6 ', 'sm6' ", '15');

Dress uniform please:

Unique Commision Amount/Commission Percentage:
PROD_ID    PROD_NAME                      SALESMAN_I SALESMAN_NAME                  COMMISSION COMMISSION
---------- ------------------------------ ---------- ------------------------------ ---------- ----------
1          prd1                           1          sm1                                       10
2          prd2                           1          sm1                            10.00
5          prd5                           1          sm1                                       15

Means, we must identify the product ID for the business that gives the same percentage of commission sales amount or commission. Percentage of different Commission amount and the Commission:

Different Commision Amount/Commission Percentage:
PROD_ID    PROD_NAME                      SALESMAN_I SALESMAN_NAME                  COMMISSION COMMISSION
---------- ------------------------------ ---------- ------------------------------ ---------- ----------
3          prd3                           2          sm2                            10.00
3          prd3                           1          sm1                            15.00
3          prd3                           3          sm3                            10.00
4          prd4                           1          sm1                            10.00
4          prd4                           2          sm2                                       15
6          prd6                           1          sm1                                       15
6          prd6                           2          sm2                                       15
6          prd6                           3          sm3                            15
6          prd6                           4          sm4                            15
7          prd7                           1          sm1                                       15
7          prd7                           2          sm2                                       15
7          prd7                           3          sm3                                       15
7          prd7                           4          sm4                                       15
7          prd7                           7          sm7                                       15
7          prd7                           5          sm1                                       10
7          prd7                           6          sm6                                       15

Means, for the highest of the product ID, assigned amount/percentage of different sales commission to sellers; that is for a product id, there is same amount/percentage of commission which would come at the first exit, if these lines of product codes should be in the second output. Kindly help me, since we use very old version, so I think that we cannot use analytics or new SQL functions.  So, please help me in a simple sql. Thank you.

I hope that this works in version 8i.

SQL > select prod_id
2, prod_name
3, salesman_id
4, salesman_name
5, commission_per
6, commission_amt
7 of)
8. Select s.*
9, mod (nvl (sum (commission_per) on (prod_id partition), 0), count (*) on (prod_id partition)) +.
10 mod (nvl (sum (commission_amt) on (prod_id partition), 0), count (*) on (prod_id partition)) val
11, row_number() over (partition by prod_id arrested by salesman_id) rno
12 s sale
13         )
14 where val = 0
15 and rno = 1;

PROD_ID PROD_NAME SALESMAN_I SALESMAN_NAME COMMISSION COMMISSION
---------- ------------------------------ ---------- ------------------------------ ---------- ----------
1          prd1                           1          sm1                                       10
2          prd2                           1          sm1                            10.00
5          prd5                           1          sm1                                       15

SQL > select prod_id
2, prod_name
3, salesman_id
4, salesman_name
5, commission_per
6, commission_amt
7 of)
8. Select s.*
9, mod (nvl (sum (commission_per) on (prod_id partition), 0), count (*) on (prod_id partition)) +.
10 mod (nvl (sum (commission_amt) on (prod_id partition), 0), count (*) on (prod_id partition)) val
11, row_number() over (partition by prod_id arrested by salesman_id) rno
12 s sale
13         )
14 where val! = 0 ;

PROD_ID PROD_NAME SALESMAN_I SALESMAN_NAME COMMISSION COMMISSION
---------- ------------------------------ ---------- ------------------------------ ---------- ----------
3          prd3                           2          sm2                            10.00
3          prd3                           1          sm1                            15.00
3          prd3                           3          sm3                            10.00
4          prd4                           1          sm1                            10.00
4          prd4                           2          sm2                                       15
6          prd6                           2          sm2                                       15
6          prd6                           1          sm1                                       15
6          prd6                           4          sm4                            15
6          prd6                           3          sm3                            15
7          prd7                           7          sm7                                       15
7          prd7                           5          sm1                                       10
7          prd7                           4          sm4                                       15
7          prd7                           3          sm3                                       15
7          prd7                           6          sm6                                       15
7          prd7                           1          sm1                                       15
7          prd7                           2          sm2                                       15

16 selected lines.

SQL >

Tags: Database

Similar Questions

Maybe you are looking for

  • Updating BIOS for Satellite C55-A-1RG can not be downloaded - 404 not found

    I can't download the update of bios for laptop Satellite C55-A-1RG.I go to http://www.toshiba-greece.com/innovation/jsp/supportMyProduct.do?LNG=28&service=SE and when I click on the link 02/12/14Update the BIOSToshiba OS independent 1, 10 - WIN World

  • Network - username & password

    We have a netbook and laptop (Wifi and Windows 7 running) who can see and transfer the content.  The main computer that is wired is on Vista, but when I go to the network, I see that they are there, when I click on them I am obliged to give a usernam

  • Storage of media file in the memory of the phone blackBerry Smartphones

    I'm puzzled. The assumption that the memory of the smartphone (I have an a BB 8310) would store media files for example tunes, or at least some of them, but every time I try and drag a file from the Media Manager in the memory of the device, accordin

  • Windows 8 - can I add multiple cities to my weather app?

    In Windows 8 on the start page on the tile of the weather, I'm wanting to know how to add other cities, so that I can see what time where family and friends live in other parts of the country and all over the world.

  • The upgrade to ESXi 4.1 with Update Manager - disconnect SAN?

    Just noticed a patch was released for ESXi 4.1, if I deploy this hotfix with Update Manager, do I have to disconnect the SAN in order to install the host?  ESXi make his case of scanning for unformatted volumes and format when it restarts first after