sql - rank over partition -


i have total of 3 tables. 1 table called contactinfo cntct_id primary index.

second table contactmap links customer(custnum) contactinfo (details suchs name, position, phone number etc).

final table complete customer list, 1 column has revolving list of our customers.

my code below pulls recent entry custnum 84574. need pull results custnum in complete customer list custlist.

select       a. cust_type     ,a.cinsert_dt     ,a.cntct_id  contactinfo  join  contactmap b on a.cntct_id = b.cntct_id        b. custnum in (‘84574’) ,         a. cust_type in (‘payer’)  qualify rank() on (partition a. cust_type order a. cinsert_dt desc) = 1 

here tables contactinfo table

cntct_id    cust_type 1           payer 2           owner 3           buyer 

contactmap table

 cntct_id       custnum 1           84574 2           99457    3           54187    

table3

 custnum 84574 99457    54187    

simply join table #3 on custnum , change partition custnum instead of cust_type:

select       a. cust_type     ,a.cinsert_dt     ,a.cntct_id  contactinfo  join  contactmap b on a.cntct_id = b.cntct_id join custlist c on b.custnum = c. custnum  --maybe remove condition , add cust_type partition if want 1 row per type a.cust_type in (‘payer’)  qualify   rank()   on (partition c.custnum          order cinsert_dt desc) = 1 

Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -