Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6725497
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:48:53+00:00 2026-05-26T09:48:53+00:00

I’m fairly new to SQL, and i’m trying to make a query with simple

  • 0

I’m fairly new to SQL, and i’m trying to make a query with simple math in the Android app.
Here’s what i’m trying to do –

I have a table named allfoods, with columns named ‘calories’ and ‘size’. Here’s the query-

int tempCalories = 100;
int maxCalories = 300;
Cursor dataFoods = myDataBase.rawQuery("SELECT id FROM allfoods WHERE size <> 0 AND (" + tempCalories + " + (calories * (size / 100)) < " + maxCalories +")" , null);

Will that work?
I have some trouble testing it myself, since the returned values are too varied.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T09:48:54+00:00Added an answer on May 26, 2026 at 9:48 am

    Hello tofira,

    Yes, your query will work, if you change the denominator to 100.0 in (size / 100.0).

    However, your query might return 0, as your equation:

    100 + (calories * (size / 100.0)) < 300

    will return false when the values for size and/or calories are out of range.

    Proof

    To test your query I created a table with data, and a tests view.

    Data

    To have something to test against, I created a table where the values for size ranged in steps of 1 from 1 to 1000 and calories ranged in steps of 5 from 5 to 5000, like this:

    Id  |   size    |   calories
    ----------------------------
    1   |   1       |   5
    2   |   2       |   10
    3   |   3       |   15
    4   |   4       |   20
    5   |   5       |   25
    

    Test

    To test your equation, I created a view to verify each step of your equation.

    SQL

    CREATE VIEW "test" AS 
        SELECT id, size AS 'S', calories AS 'C',
        size/100.0 AS 'S/100',
        calories * (size/100.0) AS 'C*(S/100)', 
        100 + (calories * (size/100.0)) AS '100+(C*(S/100))',
        CASE WHEN (300 > (100 + (calories * (size/100.0)))) 
            THEN 'true' ELSE 'false' END AS 'Eq'
        FROM allfoods;
    

    Result

    Id  |  S   |  C    |  S/100  |  C*(S/100)  |  100+(C*(S/100))  |  Eq
    ---------------------------------------------------------------------------
    62  |  62  |  310  |  0.62   |  192.2      |  292.2            |  true
    63  |  63  |  315  |  0.63   |  198.45     |  298.45           |  true
    64  |  64  |  320  |  0.64   |  204.8      |  304.8            |  false
    65  |  65  |  325  |  0.65   |  211.25     |  311.25           |  false
    66  |  66  |  330  |  0.66   |  217.8      |  317.8            |  false
    

    Conclusion

    Running your query against my test data would return row 1 to 63.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to loop through a bunch of documents I have to put
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
this is what i have right now Drawing an RSS feed into the php,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.