如何在Oracle查询中获取选定记录后具有特殊条件的第一条记录?

问题描述 投票:0回答:1

请帮忙。 我有一个显示许多记录的查询。我需要找到方法,例如:在值为“A”的记录之后获取前 3 条记录

谢谢你

CREATE TABLE "TABLETEST" 
   (
    "CUSTOMER_ID" NUMBER, 
    "VALUE" VARCHAR2(255 BYTE)
   )


INSERT INTO TABLETEST VALUES (1, 'valueb');
INSERT INTO TABLETEST VALUES (2, 'valuec');
INSERT INTO TABLETEST VALUES (3, 'valuea');
INSERT INTO TABLETEST VALUES (4, 'valueD');
INSERT INTO TABLETEST VALUES (5, 'valueF');
INSERT INTO TABLETEST VALUES (6, 'valueY');
INSERT INTO TABLETEST VALUES (7, 'valueU');
INSERT INTO TABLETEST VALUES (8, 'valueaT');

I would like to see 3 records after record customer_id= 5
oracle conditional-statements
1个回答
0
投票

我认为你只需要

Order by..fetch
声明。

SEELCT *
  FROM "TABLETEST"
 WHERE "CUSTOMER_ID" > 5
 ORDER BY "CUSTOMER_ID"
 FETCH FIRST 3 ROWS ONLY;
© www.soinside.com 2019 - 2024. All rights reserved.