Quantcast
Channel: SCN : Discussion List - PowerBuilder Developer Center
Viewing all articles
Browse latest Browse all 2881

Datawindow with SQL SubSelect? PB 12.5

$
0
0

Greetings All,

 

I have an SQL query that works great.  It does an outer join on several tables to allow one of our partners to manage their rates in our Affiliate Portal.

 

As you can see in the attached screenshot, the last column on the right is 'Rate Rank'.  I want to be able to show the affiliate where they rank relative to other affiliates for this particular city pair as 1, 2, 3, 4, etc. when multiple affiliates have rates for the same trip.  You may have seen something similar in some RFP products where as you enter your rate, you can see your rank relative to your competitors rank, but all you know is your rank.

 

I need some way to hit the database and using the key fields, get the value of "ft_affiliate_rate_staged.ar_total_from_airport" along with the affiliate's identifier (sp_id), and then sort and rank the current affiliate's rate compared to any others found in the database.

 

So if the current affiliate has a rate of $100.00 and there are a total of three affiliates that have a rate with the others coming in at $80.00 and $120.00, the current affiliate would see their rate rank as 2.

 

The important part of the key, I think, is FT_AFFILIATE_RATE_STAGED.A_IDENTITY and FT_AFFILIATE_RATE_STAGED.B_IDENTITY.  That essentially defines the trip (e.g., Ann Arbor, MI to/from airport DTW).  Other important parts of the key are vehicle type (because an affiliate can have different rates for different vehicle types (FT_AFFILIATE_RATE_STAGED.VEHICLE_TYPE) and sp_id (FT_AFFILIATE_RATE_STAGED.SP_ID) which indicates the affiliate whose rates are currently being displayed.

 

I want this to be fast as we might be displaying hundreds of rows in the datawindow.

 

Can someone kindly suggest an approach to getting this done (painless as possible, please).

 

I know I can write a function to do this with an NVO DW and simply and change ft_affiliate_rate_staged.ar_rate_rank to a computed field and call it there.  My concern is that it might not be very fast.

 

Thanks very much for any pointers or suggestions!!

 

Paul

 

 

SELECT DISTINCT

FTP.FP_CITY,

FTP.FP_POSTAL_CODE,

FAA.A_ID,

FAA.AIRPORT_IDENTITY,

FAA.A_TRAIN_STATION,

FARS.a_identity,

FARS.b_identity,

FARS.SP_ID AS SP_ID,

FARS.AR_VEHICLE_TYPE AS AR_VEHICLE_TYPE, 

FARS.AR_BASE_RATE AS AR_BASE_RATE,           

FARS.AR_GRATUITY AS AR_GRATUITY,     

FARS.AR_PARKING AS AR_PARKING,       

FARS.AR_TOLLS AS AR_TOLLS,     

FARS.AR_STC AS AR_STC,

FARS.AR_FUEL AS AR_FUEL,         

FARS.AR_EMLN AS AR_EMLN,       

FARS.AR_MEET_GREET AS AR_MEET_GREET,     

FARS.AR_HOLIDAY AS AR_HOLIDAY,

FARS.AR_AIRPORT_FEE_PU AS AR_AIRPORT_FEE_PU,

FARS.AR_AIRPORT_FEE_DO AS AR_AIRPORT_FEE_DO,        

FARS.AR_DISCOUNT AS AR_DISCOUNT,     

FARS.RT_TOTAL AS RT_TOTAL,     

FARS.r_currency AS r_currency,       

FARS.r_drivetime AS r_drivetime,       

FARS.AR_MILEAGE AS AR_MILEAGE,       

FARS.AR_RATE_RANK AS AR_RATE_RANK,

FARS.ar_update_datetime AS ar_update_datetime,

FAA.A_ID AS ROW_STATUS,

FTP.FP_IDENTITY,

FARS.ar_total_to_airport AS ar_total_to_airport,

FARS.ar_total_from_airport AS ar_total_from_airport,

FARS.ar_tax_to_airport AS ar_tax_to_airport,

FARS.ar_tax_from_airport AS ar_tax_from_airport,

FARS.ar_rate_type,

FARS.user_id

FROM             FT_PLACE FTP

INNER JOIN       FT_AIRPORT_ALL FAA ON FAA.A_ID = :a_id

LEFT OUTER JOIN  FT_AFFILIATE_RATE_STAGED FARS ON FTP.FP_IDENTITY = FARS.a_identity AND FAA.AIRPORT_IDENTITY = FARS.b_identity AND FARS.SP_ID = :sp_id AND AR_VEHICLE_TYPE = :car_type

WHERE   FTP.FP_COUNTRY = :country_code

AND     FTP.FP_STATE = :region

AND     FTP.FP_COUNTY = :subregion

ORDER BY

FTP.FP_CITY,

FTP.FP_POSTAL_CODE


Viewing all articles
Browse latest Browse all 2881

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>