SQL - Select unique rows from a group of results

前端 未结 5 1120
时光说笑
时光说笑 2021-01-25 14:44

I have wrecked my brain on this problem for quite some time. I\'ve also reviewed other questions but was unsuccessful.

The problem I have is, I have a list of results/t

5条回答
  •  滥情空心
    2021-01-25 15:38

    You want embedded queries, which not all SQLs support. In t-sql you'd have something like

    select  r.registration, r.recent, t.id, t.unittype
    from    ( 
        select  registration, max([date]) recent
        from    @tmp 
        group by 
            registration
        ) r
    left outer join 
        @tmp t 
    on  r.recent = t.[date]
    and r.registration = t.registration 
    

提交回复
热议问题