日期:2014-05-17 浏览次数:20747 次
SELECT [user] ,
列2 ,
SUM(列4) 列4
FROM ( SELECT [user] ,
列2 ,
列3
FROM TB
WHERE 列3 = 1
UNION ALL
SELECT [user] ,
列2 ,
-1 * 列3
FROM TB
WHERE 列3 = -1
) a
GROUP BY [user] ,
列2
select
a.[user],
a.[列2],
datediff(mi,'2000-01-01 '+a.[列4],'2000-01-01 '+b.[列4])
from table a inner join table b
on a.[user]=b.[user]
and a.[列2]=b.[列2]
and a.[列3]<>b.[列3]
where a.[列3]=1