|
| How to retrive values based on Slabs |
| Iniciado por guest, 16,oct. 2017 14:31 - 3 respuestas |
| |
| | | |
|
| |
| Publicado el 16,octubre 2017 - 14:31 |
Hello,
I have a table whose structure is: p_product_id p_weight p_rate This table contains following data: p_product_id p_weight p_rate 1 0.250 1 1 0.500 4 1 0.750 7 1 0.900 7.5 1 1.000 10 2 0.250 2 2 0.500 3 2 1.150 10.5 3 0.700 6.5 3 0.900 7.5
Now when a user enters Weight I need to find the rate applicable.
So if user enters weight of 0.600 then based on the product selected the rate applicable is that of 0.750 that is 7
What query should I use for retrieving this rate?
TIA |
| |
| |
| | | |
|
| | |
| |
| Publicado el 16,octubre 2017 - 15:00 |
Not tested but try something like this:
select s.p_rate from your_table s where s.p_product_id=the produtct you need and s.p_weight = (select min(w.p_weight) from from your_table w where s.p_product_id=w.p_product_id and w.p_weight>= your_input weight) |
| |
| |
| | | |
|
| | |
| |
| Publicado el 16,octubre 2017 - 15:01 |
Yogi,
if your logic needs to be the perfect match or take the next higher weight this query should do the trick.
select * from table where p_weight >= %1 and p_product_id = 'ProductID' order by p_weight asc limit 1;
cheers, Sascha |
| |
| |
| | | |
|
| | |
| |
| Publicado el 17,octubre 2017 - 06:10 |
Sascha,
Quote Sascha77
if your logic needs to be the perfect match or take the next higher weight this query should do the trick.
select * from table
where p_weight >= %1
and p_product_id = 'ProductID'
order by p_weight asc
limit 1; That is great. It does the trick for me! And it works like a charm.
Thanks for this simple and workable solution.
Regards, |
| |
| |
| | | |
|
| | | | |
| | |
|