Math filter in "query all records"
![Valentin R](https://us.v-cdn.net/6037124/user_avatars/4304535.jpg)
I am trying to find a way to do the following:
1. There is a db with columns A and B
2. I want to get only the records where A/B>0.2
3. B values are sometimes 0, so I am using AND condition where B>0 and A/B>0.2 (with "div" math filter).
But the result of this query is very far from the truth. What's the catch?
Thanks.
Best Answer
-
I don't think you need to change the db type. If you just add 0.0 to the numerator, this will kick the database into thinking in floating point math rather than integer math. I attached a screenshot illustrating the point
Answers
-
Hi, @Valentin R. Can you post a quick screenshot of your custom query?
-
Hi Chris,
here is that part, but the query is more complex - there are a few other nested AND/OR conditions, but those work fine. -
Hi,
By very far from the truth you mean you are getting errors or just incorrect results?
-
are click_count and send_count integers? If so, we need to cast them to floats as we do the division. In integer math, 1/5 is the same as 3/5: 0. If we cast them to floats, 1.0/5.0 is not the same as 3.0/5.0 - 0.2 vs 0.6
-
@Pawel Magdanski incorrect results (like 80 records instead of a few thousand), probably for the reason Ray gave.
@Ray Deck those are integers, yep. I suspected it! And by "cast" do you mean that I need to change the type of the field in db? -
Thanks, @Ray Deck , this works!
Categories
- All Categories
- 53 ? Announcements
- 47 ? Releases
- 37 ? Welcome
- 983 ? Help! I'm a Noob
- 125 ? No-Code Front-Ends
- 633 ? Working with APIs
- 439 ? Transforming data
- 126 ? Connect Xano to ...
- 50 ?? Find an Expert
- 348 ❓Other questions
- 35 ? Security
- 22 ✂️ Snippets
- 19 ? Showcase
- 7 ?️ Xano Chatter
- 62 ? Video Tutorials
- 171 ? Request a feature
- 229 ? Report a Bug
- 19 ? Templates & Extensions
- 7 ? Feedback