日期:2014-05-16  浏览次数:20503 次

SELECT DISTINCT无法查询非聚合列,这样的查询还有办法吗?
本帖最后由 walkm01 于 2014-05-08 11:32:03 编辑



请教下如何写语句,disctict只能查询出唯一的姓名,但是最后时间出入库状态无法查出
------解决方案--------------------
select * from tb a
where exists (select 1 from (
select 姓名,max(时间)时间
from tb
group by 姓名)b where a.姓名=b.姓名 and a.时间=b.时间)

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

select a.* from tb a where exists( select 1 from tb where 姓名=a.姓名 and a.id =max(id) group by 姓名)