Caculate Database Fields Against Each Other

Options
I'm trying to figure out the best way to word what I'm doing so let me just tell you what I'm trying to accomplish:

On my DB table you can see I have a list of products and along with those products I have prices from 3 different merchants.[image.png]
On the front-end I want to be able to primarily sort the listing based on which product has the lowest price. Since there isn't a single price (the product is sold across many stores at different prices) I want to be able to automatically show the price that is the lowest.

But I also want to have other ways of sorting the products such as which has the biggest discount amount (MSRP minus Lowest_Price) or the biggest discount percentage (1 minus the sum of Lowest_Price divided by MSRP)

I have two main questions:
1.  Do I need to "hard code" these values into the database or is this something the API endpoint can calcuate and print in the results whenever it's called?
2. How (and where) would I make these calcuations? The most difficult one in my mind is having a calcuation that looks at a set of fields (such as the three different merchants) and then prints the value that is the lowest of them.

Comments

  • Ray Deck
    Ray Deck Trusted Xano Expert ✭✭✭
    Options
    Do the query to get the data, then use the function stack to post-process and sort it. The difficulty is in thinking through the logic, not the mechanics of implementing the stacked loops, conditionals and functions. I was just helping another Xano user do this via a coaching engagement a couple weeks back.