WeTi
asked on
SQL divide query
Dear expert i need help on this sql query:
select sum (money)
from dayground
where Daycode = 1 and Typecod = 4 and date = '20790606'
and money >= 25000
divide by
select count (memberno)
from dayground
where Daycode = 1 and Typcod = 4 and date = '20790606'
and money >= 25000
Anyway to do it?
Thx
select sum (money)
from dayground
where Daycode = 1 and Typecod = 4 and date = '20790606'
and money >= 25000
divide by
select count (memberno)
from dayground
where Daycode = 1 and Typcod = 4 and date = '20790606'
and money >= 25000
Anyway to do it?
Thx
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
What database?
Am I missing the reason you cannot do:
You will need to worry when the count = 0. What do you want to happen then? It would likely be a CASE statement.
Am I missing the reason you cannot do:
select sum (money)/count (memberno)
from dayground
where Daycode = 1 and Typecod = 4 and date = '20790606'
and money >= 25000
You will need to worry when the count = 0. What do you want to happen then? It would likely be a CASE statement.
ASKER
One more thing, how do you round the result to 0 decimal?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
you can surely cast:
select cast (
(
select sum (money)
from dayground
where Daycode = 1 and Typecod = 4 and date = '20790606'
and money >= 25000
)
/
(
select count (memberno)
from dayground
where Daycode = 1 and Typcod = 4 and date = '20790606'
and money >= 25000
)
as int)
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Because im a beginner and didn't know how to use cast fully
ASKER