SELECTa.车牌号码,b.操作时间 FROM总表 AS aLEFT JOIN 操作记录 AS b ON a.车牌号码 = b.[车牌号码] WHEREa.车牌号码 = 'H18976'我想只取最后一次数据 应该如何写 不懂 麻烦告知一下谢谢
SELECT 车牌号码, 操作时间 from ( SELECT a.车牌号码, b.操作时间, row_number() over (partition by a.车牌号码 order by b.操作时间 desc) as rn FROM 总表 AS a LEFT JOIN 操作记录 AS b ON a.车牌号码 = b.[车牌号码] WHERE group by a.车牌号码 ) t where rn=1