1

例 -

select * from discussion where title like '%india%' 
UNION 
select * from discussion where title like '%Australia%'

両方のタイプの結果を混合したディスカッションIDの順序で結果が表示されます

最初にインドの結果を表示し、次にオーストラリアの結果を表示したいのですが、重複する行も削除する必要があるため、オプションAL1を使用できません。

何をすべきですか?

4

3 に答える 3

5

注文する列を追加できます

select *, 1 as ORD from discussion where title like '%india%' 
UNION 
select *, 2 as ORD from discussion where title like '%Australia%'

order by ORD

編集-2010年11月29日

ORDの問題が重複しているため、これを達成するためのよりエレガントな方法を考えていました。

Select * from discussion
where title like '%india%' or title like '%Australia%'
order by (case when title like '%india%'then 1 else 2 end)
于 2010-11-02T08:44:04.913 に答える
1

試す:

SELECT * FROM
(
  select 1 OrderNo, d.* from discussion d where title like '%india%' 
  UNION 
  select 2 OrderNo, d.* from discussion d where title like '%Australia%'
)
ORder by OrderNo
于 2010-11-02T08:43:22.963 に答える
0
select * from
(
select * from discussion where title like '%india%' 
UNION 
select * from discussion where title like '%Australia%'
)
ORDER BY title DESC
;
于 2010-11-02T08:45:43.400 に答える