MacRumors Forums Resolved: Math in SQL? (HW)

Feb 22, 2013, 05:07 PM   #1
ArtOfWarfare
macrumors 603

Join Date: Nov 2007
Math in SQL? (HW)

I haven't even had 3 hours of hands on time with SQL yet, so I'm sorry if this comes off sounding like a very noobish question, but I can't figure out what I need to do to take the number returned by this query:

Code:
```SELECT description, deaths1 FROM who.deaths
INNER JOIN who.icd9
ON who.deaths.cause = who.icd9.cause
where sex = 2
and country in (SELECT country FROM who.country where country_name like '%united kingdom%')
and ryear = 1980
and deaths1 > 0
group by who.icd9.cause
order by deaths1 desc
limit 1;```
And divide it by a number returned by a different query.

Specifically, the question from my homework assignment is
Quote:
 What percentage of the United Kingdom's female population died in 1980 from the leading cause of death?
The query I wrote above returns what the leading cause of death is for the United Kingdom Females from 1980, but now I need to sum all of the deaths for the United Kingdom Females from 1980 and then divide it by that.

I can't make what I've already written a subquery, because MySQL complains that it doesn't support limits inside of subqueries.

Suggestions?

Edit:

Alright, I can separately find the sum of all UK female deaths from 1980 with this query:

Code:
```SELECT SUM(deaths1) deaths1 FROM who.deaths
where sex = 2
and country in (SELECT country FROM who.country where country_name like '%united kingdom%')
and ryear = 1980;```
I don't know how to divide one by the other, though.
__________________
Don't tell me Macs don't last: 2007 iMac, 2007 Mac Mini, 2008 MacBook Air, all Vintage.
(iMac obsoletion: April 28, 2015, MBA: October 14, 2015, Mac Mini: March 9, 2016)

Last edited by ArtOfWarfare; Feb 22, 2013 at 09:53 PM.
0

 MacRumors Forums