日期:2014-05-18 浏览次数:20654 次
select * from table_name where type <> 3
union all
select B.* from
(
select distinct name
from table_name
where type = 3
) A
cross apply
(
select top(1) * from table_name
where name = A.name
) B
------解决方案--------------------
select id,name,secondname,type from from t where type <3 union all select max(id),max(name),secondname,max(type) from t where type = 3 group by secondname having count(secondname) = 2
------解决方案--------------------
select distinct * from tb
------解决方案--------------------
select id,name,secondname,type
from from t
where type <3
union all
select max(id),max(name),secondname,max(type)
from t
where type = 3
group by secondname
having count(secondname) = 2