帮忙看一小问题
我一sql语句查出来结果:
select BlockName from A
BlockName
--------------------
-请选择版块-
黄浦滨江板块
打浦桥板块
淮海中路板块
-请选择版块-
我现在要去掉重复,如果用distnict 顺序会变了。我不希望变,该怎么处理。
用distinct 会变成
select distinct BlockName from A
BlockName
--------------------
打浦桥板块
黄浦滨江板块
淮海中路板块
-请选择版块-
我希望成为:
BlockName
--------------------
-请选择版块-
黄浦滨江板块
打浦桥板块
淮海中路板块
------解决方案--------------------select distinct BlockName from A order by case BlockName when '黄浦滨江板块 ' then 1 when '打浦桥板块 ' then 2 when '淮海中路板块 ' then 3 end
------解决方案--------------------试一下
select BlockName from A group by BlockName having count(1)=1
------解决方案--------------------输出到临时表,再从临时表输出
select identity(int,1,1) id,blockname into #tmp from A
delete a from #tmp a where exists(select * from #tmp where blockname=a.blockname and id <a.id)
select blockname from #tmp
drop table #tmp