I am new to Sql server. the sum(datediff(x,y,z)) is giving the sum of both a1 and a2 whereas I want the sum separate for a1 and a2. I dont know how to group it per id. I know that sum will return the sum of both but I want to know how can I separate them.
select email,
sum(datediff(day, x, y))
from abc
where users.id ='a1'
or users.id='a2'
group by email, users.id
email|datex|datey|
a1 |1 |2
a1 |1 |3
a1 |2 |5
a2 |2 |7
a2 |3 |7
a2 |1 |8
So what I need
email|diff
a1 |4
a2 |6
Aucun commentaire:
Enregistrer un commentaire