Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 query with SUM operator

Author  Topic 

manlio78
Starting Member

2 Posts

Posted - 2009-06-05 : 09:23:07
I have this query:

select CodLiteral, SUM(Miles*duraSof)/SUM(duraSof) as AscoltoMedio, ( (SUM(Miles * durasof)/ SUM(DURASOF)) / (SUM(ttv*durasof)/SUM(durasof)) *100) as ShareMedio
from histinformativos hi INNER join informa i on hi.codLiteral = i.codigoLit AND i.fecha=hi.fecha
WHERE month(i.fecha) = 5 AND year(i.fecha)=2009
GROUP BY CodLiteral

I want to simplify with a sub query that divide the sums per other sums?...How can I do it?

Thank you
Manlio

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-06-05 : 13:46:38
[code]
SELECT CodLiteral, AscoltoMedio, AscoltoMedio*100.0/Sum2
FROM
(
select CodLiteral, SUM(Miles*duraSof)*1.0/SUM(duraSof) as AscoltoMedio,SUM(ttv*durasof)*1.0/SUM(durasof) AS Sum2
from histinformativos hi INNER join informa i on hi.codLiteral = i.codigoLit AND i.fecha=hi.fecha
WHERE month(i.fecha) = 5 AND year(i.fecha)=2009
GROUP BY CodLiteral
)t
[/code]
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-06-08 : 03:04:04
Here is why you need to use 1.0
http://sqlblogcasts.com/blogs/madhivanan/archive/2008/01/16/beware-of-implicit-conversions.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

manlio78
Starting Member

2 Posts

Posted - 2009-06-08 : 07:10:53
thank you

Bye
Manlio
Go to Top of Page
   

- Advertisement -