sql - select unique values in one column and match with the criteria in another column -
need group table below (1) ouput table (2) these sample values, in real they're corresponding numbers , code. id should unique , code should match criteria ( if xz exists xz; if xz , xy exists select xy , on) tried 'if exists' , 'case when..then' not luck far, since both column have pk . use sql server 2008, thanks
id code 101 xz 102 xz 102 xy 103 xz 103 xa output 101 xz 102 xy 103 xa
study ranking functions , of great in grouping queries.
with cte ( select id,code, row_number() over(partition id order code) row tablename ) select id,code cte row=1
Comments
Post a Comment