Home > Software design >  How to calculate Body fat content in sql query
How to calculate Body fat content in sql query

Time:04-15

Formula

for Women (1.20 x BMI) (0.23 x Age) - 5.4 for male (1.20 x BMI) (0.23 x Age) - 16.2

I want to create an SQL query to calculate the Body fat content using the above formula. lets say BMI = 24 and age = 28

CodePudding user response:

You could use a CASE for the conditional expression. For example, with a column named Gender:

SELECT
  CASE Gender 
     WHEN 'female' THEN (1.20 * BMI)   (0.23 * Age) - 5.4
     WHEN 'male'   THEN (1.20 * BMI)   (0.23 * Age) - 16.2
  END
FROM dbo.YourTable;

CodePudding user response:

Did you wanted to put it in a select? If so you could just use this:

((1.20 x BMI) (0.23 x Age)) - (5.4 for male (1.20 x BMI) (0.23 x Age) - 16.2) AS WOMEN_BODY_FAT

Your BMI and AGE will also getting value automatically if there are containt in the table WOMAN.

  • Related