我有一个表中的列获得第一行与空
drop TABLE "public"."opportunities";
CREATE TABLE "public"."opportunities" (
"itemcode" VARCHAR COLLATE "default",
"creationtime" TIMESTAMPTZ(6) NOT NULL,
"finishtime" TIMESTAMPTZ(6),
"ordertag" INT8,
"trackingblob" VARCHAR
);
insert into opportunities VALUES ('1', now(), null, NULL, 'blob1');
insert into opportunities VALUES ('1', now(), null, 2, 'blob2');
insert into opportunities VALUES ('1', now(), null, null, 'blob3');
insert into opportunities VALUES ('2', now(), null, NULL, 'blob1a');
insert into opportunities VALUES ('2', now(), null, 2, 'blob2a');
insert into opportunities VALUES ('2', now(), null, null, 'blob3a');
预期的结果将与blob1和blob1a行。
我想获取每个orderTag,OrderTag的前一个条目的跟踪blob为null - 可能会有时间戳之后的行应该被忽略。 这是可能在一个单一的SQL或我需要用两个步骤编写程序?
您可以添加一些样本数据和预期结果(包含样本数据)吗? – jarlh
我已经按要求添加了一个样本。 – weismat
如果blob3有一个OrderTag - 应该返回blob2还是blob1? – jarlh