oracle - Using a pl-sql procedure or cursor to select top 3 rank -


can please tell how can results below.

using dense_rank function rank <=2 give me top 2 offers.

i looking 'total_offer' should sum of 'offer1' , 'offer2'. when there no offer2 ( eg:taurus) 'total offer' should 'offer1' , 'null' 'offer2'

input:

customer    make    zipcode offer mark            focus   101 250   mark             focus  101 2500   mark             focus  101 1000   mark             focus  101 1500   henry   520i    21405   500   henry   520i    21405   100   henry   520i    21405   750   henry   520i    21405   100   mark            taurus  48360   250     mark            mustang 730 500   mark            mustang 730 1000   mark            mustang 730 1250   

desired output:

 | customer | make | zipcode | top_offer1 | top_offer2 | total_offer |    | henry | 520i | 21405 | 750 | 500 | 1250    | mark | focus | 101 | 2500 | 1500 | 4000    | mark | mustang | 730 | 1250 | 1000 | 2250    | mark | taurus | 48360 | 250 | null| 250 |    

try this....

select * ( select customer,make,zipcode,offer, dense_rank() on (partition customer order customer,make, zipcode,offer desc) rank tablename) rank <4; 

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -