--建立测试环境create table tmp(A varchar(20),B char(3),C int)insert Into tmp(A,B,C)select '2005-9-9','DEC',1union select '2005-9-10', 'DEC',2Union select '2005-9-9', 'SEC',1union select '2005-9-10', 'SEC',2--根据要求过滤数据select a.a,a.c,a.DEC,b.SECfrom(Select A,C,Case B when 'DEC' then 'DEC' end DECfrom tmp) a inner join (Select A,C,Case B when 'SEC' then 'SEC' end SEC from tmp ) b On a.A = b.A and a.c =b.Cwhere a.DEC is not null and b.SEC is not nullorder by a.c