PROFESSIONAL NEWSGROUPS
WINDEV
,
WEBDEV
and
WINDEV Mobile
Home
|
Recent messages
|
Connect
|
Sign out
|
English
Home
→
WINDEV 2024
→
How to retrive values based on Slabs
How to retrive values based on Slabs
Started by Yogi Yang, Oct., 16 2017 2:31 PM - 3 replies
Connect yourself…
Yogi Yang
#1
Posted on October, 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
Report
0
0
Paulo Oliveira
#2
Posted on October, 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)
Report
0
0
Sascha77
#3
Posted on October, 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
Report
0
0
Yogi Yang
#4
Posted on October, 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,
Report
0
0
→ Go back to WINDEV 2024
WINDEV 2024
WEBDEV 2024
WINDEV Mobile 2024
WINDEV (earlier versions)
Français
English
Español
Portuguesa
Close this window
Search type
Only topics
All the messages
Search period
Any time
Past hour
Past 24 hours
Past week
Past month
Past year
Cancel
Preview of your message
Adding an image
Import an image from a URL
Send an image from a file of your disk
Drop a file or click "Browse..."
or
Cancel
0%
WLanguage
SQL
XML, HTML
JAVA, Javascript
Text