Home > front end >  BASIC Questions: Using ROUND for calculations
BASIC Questions: Using ROUND for calculations

Time:12-18

I am in Google's Data Analytics course and every now and then I get to a spot where I could just press on, but I want to know the answer anyway.

We are learning embedded calculations and a very simply equation was given: `

SELECT  
  Date,
  Region,
  Total_Bags,
  Small_Bags,
  (Small_Bags / Total_Bags) * 100 AS Small_Bags_Percent
  

FROM `shaped-fx-370703.avocado_data.avocado_prices`

WHERE
  Total_Bags <> 0

` Resulting column from calculation

I would like to know how to use ROUND so that the result in Small_Bags_Percent only go out to 1 decimel

I understand the syntax of round is ROUND(integer,decimel places) but I don't know how to point the "integer" to the results in Small_Bags_Percent. I've tried THEN and even

 ROUND(((Small_Bags / Total_Bags) * 100 AS Small_Bags_Percent),2)
``` (hey, I'm just seeing what sticks lol)

CodePudding user response:

The ROUND function goes round the calculation but not the alias for the calculation e.g.

ROUND((Small_Bags / Total_Bags) * 100,2) AS Small_Bags_Percent
  • Related