From: Plamen Ratchev on
Try this:

SELECT Hora, SUM(H_SVazio) AS total_H_SVazio
FROM (
SELECT CONVERT(CHAR(2), Data_Hora, 108) AS Hora,
ID_Contador,
MAX(E_SVazio) - MIN(E_SVazio) AS H_SVazio
FROM Contadores
JOIN DadosContadores
ON ID_Contador = ID
WHERE Data_Hora >= '20100423'
AND Data_Hora < '20100424'
AND E_SVazio <> 0
AND Uni_Fab = 'Xoli'
GROUP BY CONVERT(CHAR(2), Data_Hora, 108), ID_Contador) AS T
GROUP BY Hora
ORDER BY Hora;

--
Plamen Ratchev
http://www.SQLStudio.com
From: Henrique on
Huff...Hufff
Whork fine thanks very much.
Have a nice day

Henrique



"Plamen Ratchev" wrote:

> Try this:
>
> SELECT Hora, SUM(H_SVazio) AS total_H_SVazio
> FROM (
> SELECT CONVERT(CHAR(2), Data_Hora, 108) AS Hora,
> ID_Contador,
> MAX(E_SVazio) - MIN(E_SVazio) AS H_SVazio
> FROM Contadores
> JOIN DadosContadores
> ON ID_Contador = ID
> WHERE Data_Hora >= '20100423'
> AND Data_Hora < '20100424'
> AND E_SVazio <> 0
> AND Uni_Fab = 'Xoli'
> GROUP BY CONVERT(CHAR(2), Data_Hora, 108), ID_Contador) AS T
> GROUP BY Hora
> ORDER BY Hora;
>
> --
> Plamen Ratchev
> http://www.SQLStudio.com
> .
>