2017-12-04 1 views
0

私は私が要件ごとにクエリの一部を変更する時に1つのデータベースとの時間を持っています。 は、私は1つのテーブルにこれらのクエリの結果の前と後の両方の結果の記録を維持したいとの違いを生成するクエリを示したいと思います。和解オートメーションクエリ

例えば、 は私のクエリの前に、今、次の表

emp_id country  salary 
--------------------- 
1   usa   1000 

2   uk   2500 

3   uk   1200 

4   usa   3500 

5   usa   4000 

6   uk   1100 

を考えるには、次のとおりです。クエリの前に

select count(emp_id) as count,country from table where salary>2000 group by country; 

結果の前に:

count  country 

2  usa 

1  uk 

クエリ後:

select count(emp_id) as count,country from table where salary<2000 group by country; 

クエリ結果後:

column 1 | column 2 | column 3 | column 4 | 

2    usa   2    uk 

1    uk    1    usa 

......が、クエリ結果が同じである場合:私はしたい

count  country 

2  uk 

1  usa 

私の最終的な結果や表でありますこの表には示してはいけません。

ありがとうございます。

答えて

0

私はあなたがhereと同じアプローチを使用することができると信じています。

select t1.*, t2.* -- if you need specific columns without rn than you have to list them here 
from 
(
    select t.*, row_number() over (order by count) rn 
    from 
    (
    -- query #1 
    select count(emp_id) as count,country from table where salary>2000 group by country; 
    ) t 
) t1 
full join 
(
    select t.*, row_number() over (order by count) rn 
    from 
    (
    -- query #2 
    select count(emp_id) as count,country from table where salary<2000 group by country; 
    ) t 
) t2 on t1.rn = t2.rn