2016-06-01 4 views
1

ビットごとの演算子のPostgres:私はテーブルを取得したいビット演算子で私のようなバイナリ値含むテーブル持って

DBID BinaryTogether 
1 15 
1 12 
1  6 

binaryid description 
1   description1 
2   description2 
4   description3 
8   description4 

を私は値が含まれている別のテーブルを持っています

DBID BinaryTogether BitwiseResult 
1  15    description1,description2,description3,description4 
1  12    description3,description4 
1  6    description2, description3 
+0

[正確に同じ質問](http://stackoverflow.com/q/37575033/479863)に数時間前に質問して削除しました。もう一度、何か試してみたり、[細かいマニュアル](https://www.postgresql.org/docs/current/static/functions.html)を読んで何かを理解していないのですか? –

答えて

1

&を使用してこれらのテーブルを結合することができますその後、string_agg関数を使用して記述を集約します。ここに例があります:

with 
    b(x,d) as (
    values 
     (1,'description1'), 
     (2,'description2'), 
     (4,'description3'), 
     (8,'description4')), 
    p(y) as (
    values 
     (15), 
     (12), 
     (6)) 
select 
    y, 
    string_agg(d,',') 
from 
    p join b on (x & y != 0) 
group by 
    y 
関連する問題