PC SOFT

GRUPOS DE DISCUSSÃO PROFISSIONAL
WINDEVWEBDEV e WINDEV Mobile

Inicio → WINDEV 2024 → How to retrive values based on Slabs
How to retrive values based on Slabs
Iniciado por Yogi Yang, out., 16 2017 2:31 PM - 3 respostas
Publicado em outubro, 16 2017 - 2:31 PM
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 em outubro, 16 2017 - 3:00 PM
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 em outubro, 16 2017 - 3:01 PM
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 em outubro, 17 2017 - 6:10 AM
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,