2017-05-09 9 views
1

PostgreSQLでは、3つの異なるテーブルの値の可能なすべての組み合わせを、一意の文字列としてアンダースコア_で区切って作成したいと考えています。 可能なすべての組み合わせを作成する

diesel_black_true 
diesel_blue_true 
diesel_red_true 
diesel_black_false 
diesel_blue_false 
diesel_red_false 
gasoline_black_true 
gasoline_red_true 
... 

はそれが一般的でダイナミックな方法で可能であり、それは理にかなってホープ:私はすべての値が含まれていビューをしたいと思い

table car_type 
column 'type' contains: diesel, gasoline, electric 

table car_color 
column 'color' contains: black, blue, red 

table car_stereo 
column 'checked' contains: true, false 

例:?

答えて

3

あなたはすべての組み合わせを取得するには、テーブルをCross Joinでき

Select t.type||'_'||c.color||'_'||s.checked 
From car_type t 
Cross join car_color c 
Cross join car_stereo s; 
関連する問題