I wrote a simple query to find the percentage of two columns, but I want the results to be in a column with only two decimal places. This is what I wrote but I'm getting an error and I can't seem to fix it.
SELECT Small_Bags, Total_Bags, (Small_Bags / Total_Bags) * 100 AS Small_Bags_Percent (Select CAST (Small_Bags_Percent AS DECIMAL (10,2))) FROM Table_Bags WHERE Total_Bags <>0
You cannot use column aliases in the same query. you can do it.
Or use subquery