如果查单个号码的最后一次记录,我用select top 1 * from tb order by time desc。 请问如果是多个号码如何查询, 除了select top1 * from where sim=(sim1) union (... sim=sim2) ..这样的方式。
------解决方案--------------------
SQL code
SELECT sim, MAX(time)
FROM tb
WHERE SIM IN(SIM1,SIM2,SIM3,...)
GROUP BY sim
ORDER BY time DESC
------解决方案-------------------- MSSQL2005及以上版本: ;with aaa as ( select row_number() over(partition by 目的号码 order by 通话时间 desc) as row,* from table1 ) select * from aaa where row=1 and 目的号码 in (你要查询的号码列表,比如'123','234'...)
------解决方案--------------------