日期:2014-05-17  浏览次数:20735 次

一条SQL语句不知道怎么写 ,求助
我有一表:a     xmid:项目id     money:钱        bbh:版本号   times:时间

xmid           money         bbh               times

101           10            1.1版本            2013.12.6
101           20            1.1版本            2013.12.6
101           30            1.1版本            2013.12.6

102           10            1.1版本            2013.12.6

101           20            1.2版本            2013.12.7
101           20            1.2版本            2013.12.7

问题是我现在想
查询出来的数据如:
101           40(合并)          1.2版本            2013.12.7(时间最后插入)
102           10(合并)        1.1版本            2013.12.6(时间最后插入)

------解决方案--------------------

select id,sum([money]),bbh,times from #temp
where (id = 102 and times = (select top 1 max(times) from #temp where id = 102)) or 
(id = 101 and times = (select top 1 max(times) from #temp where id = 101))
group by id,bbh,times

------解决方案--------------------

select id,sum([money]),bbh,times from #temp c
where id in(select t.id from