は、それはそうですあなたはどのようにしてグループの指示を尋ねている可能性があります - すなわち、グループはそのグループの最初の行にのみ表示されます。その場合、lag()ウィンドウ関数を使用します。あなたがいるなら
select p.plantId, p.color, v.Feeldesc
from plant p left join vegetable v using (plantId)
order by plantId, vegetableId;
:あなたは(モジュラス列見出し)を示した結果は、この単純なクエリを得ることができ
create table plant (plantId int not null primary key, color text not null);
create table vegetable (vegetableId int not null, plantId int not null,
Feeldesc text not null, primary key (vegetableId, plantId));
insert into plant values (1,'Red'),(2,'Green'),(3,'Purple');
insert into vegetable values (199,1,'Harsh'),(200,1,'Sticky'),
(201,2,'Bitter'),(202,3,'Bland');
:スキーマとデータのセットアップを想定し
はこのようなものです最初の行以降の繰り返し情報の表示を抑制するには、このクエリで行います。
select
case when plantId = lag(plantId) over w then null
else plantId end as plantId,
case when p.color = lag(p.color) over w then null
else p.color end as color,
v.Feeldesc
from plant p left join vegetable v using (plantId)
window w as (partition by plantId order by vegetableId);
の結果は次のようになります。
plantid | color | feeldesc
---------+--------+----------
1 | Red | Harsh
| | Sticky
2 | Green | Bitter
3 | Purple | Bland
(4 rows)
私が読んで、エンドユーザーのために簡単だったのpsqlから直接リストを生成するためにちょうど今週上記のような何かをしなければなりませんでした。そうでなければ、あなたはこの機能について質問しているかもしれません。うまくいけば、これはあなたの質問に答えますが、私は完全に基盤を離れているかもしれません。
2つの 'Red'エントリについては、' Feeldesc'の値が異なるので、どちらを返すのですか? – sll
上記の結果で何が起こるのですか? 'Red Harsh'と' Red Sticky'は全く同じで、あなたはそれを排除したいので、ルールを決める必要があります。 –
よく、野菜のテーブルからあなたはどんな列ですか? – dotjoe