PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, January 24, 2022

[FIXED] How to extract data which lies in a range in Sql

 January 24, 2022     mysql, phpmyadmin, sql     No comments   

Issue

I'm writing an android application which sends a particular value of carbohydrates,proteins and fats to the server. My database contains food items which also mentions the amount of carbohydrates, proteins and fats contained in those food items.

I would like to know how to query the database to return the food items which have the values similar to that sent by the app.

ex: Suppose the app sends carbohydrates,proteins and fats as 30,40 and 50 gm to the server. Then the server should extract and send back food items which has carbohydrates in the range of 29-31, proteins in the range of 39-41, fats in the range of 49-51

The food table has list of food items and the columns are of carbohydrates, proteins and fats

sample database

From the example I need to get the similar food items i.e brown bread,white bread and almond.


Solution

Try this:

SELECT * FROM Breakfast
WHERE ? between carbohydrate_m - 1 and carbohydrate_m + 1
AND ? between protein_m - 1 and protein_m + 1 
AND ? between fat_m - 1 and fat_m + 1


Answered By - Gurwinder Singh
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing