# Update table from sum and group by of another one?

### Question

• I have a Table_total that has Total1, Total2, Total3 and Percent.

Essentially, I need to divide Total3 by the max between Total1 and Total2. So if Total1  > Total2, then Percent = Total1/Total3. Else, Percent = Total2/Total3.

Thanks.

VM

Wednesday, April 03, 2013 8:05 PM

• Hi

To simply select the percent

Select  Case When Total1 > Total2 Then Total1/Total3 Else Total2/Total3 End as Percent  From Table_Total

To update:

Update Table_Total

Set Percent =  Case When Total1 > Total2 Then Total1/Total3 Else Total2/Total3 End

- will

- will

Wednesday, April 03, 2013 8:09 PM

### All replies

• Hi

To simply select the percent

Select  Case When Total1 > Total2 Then Total1/Total3 Else Total2/Total3 End as Percent  From Table_Total

To update:

Update Table_Total

Set Percent =  Case When Total1 > Total2 Then Total1/Total3 Else Total2/Total3 End

- will

- will

Wednesday, April 03, 2013 8:09 PM
• Oh and you probably want to check for a divide by zero error...just in case!

- will

Wednesday, April 03, 2013 8:09 PM