我需要根据优先级对来自多个来源的大量数据进行分组,但这些来源的数据质量不同 - 它们可能会丢失一些数据。任务是以尽可能完整的方式将这些数据分组到一个单独的表中。
例如:
create table grouped_data (
id serial primary key,
type text,
a text,
b text,
c int
);
create table raw_data (
id serial primary key,
type text,
a text,
b text,
c int,
priority int
);
insert into raw_data
(type, a, b, c, priority)
values
('one', null, '', 123, 1),
('one', 'foo', '', 456, 2),
('one', 'bar', 'baz', 789, 3),
('two', null, 'two-b', 11, 3),
('two', '', '', 33, 2),
('two', null, 'two-bbb', 22, 1);
Run Code Online (Sandbox Code Playgroud)
现在我需要对记录进行分组 …