求sql语句(高手来)
数据库
id name b time
1 张 30 2007-7-19
2 张 20 2007-7-18
3 李 200 2007-7-19
4 李 100 2007-7-18
5 李 290 2007-7-17
我要取出最近2天的同一name的记录,b做差
------解决方案----------------------指昨天和前天?
select t1.name , t1.b - t2.b b from
(select name , b from tb where datediff(day,time,getdate()) = 1) t1,
(select name , b from tb where datediff(day,time,getdate()) = 2) t2
where t1.name = t2.name