Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to write query ?

PV5253May 7 2019 — edited May 8 2019

Hi Experts,

I need below output but not able to write query. Please fix it.

CREATE TABLE TBL(FIRST_NAME VARCHAR2(20)) ;

/

INSERT INTO TBL (FIRST_NAME) VALUES ('ELLEN');

INSERT INTO TBL (FIRST_NAME) VALUES ('SUNDAR');

INSERT INTO TBL (FIRST_NAME) VALUES ('MOZHE');

INSERT INTO TBL (FIRST_NAME) VALUES ('DAVID');

INSERT INTO TBL (FIRST_NAME) VALUES ('HERMANN');

INSERT INTO TBL (FIRST_NAME) VALUES ('SHELLI');

INSERT INTO TBL (FIRST_NAME) VALUES ('AMIT');

INSERT INTO TBL (FIRST_NAME) VALUES ('ELIZABETH');

INSERT INTO TBL (FIRST_NAME) VALUES ('SARAH');

INSERT INTO TBL (FIRST_NAME) VALUES ('DAVID');

INSERT INTO TBL (FIRST_NAME) VALUES ('LAURA');

INSERT INTO TBL (FIRST_NAME) VALUES ('HARRISON');

INSERT INTO TBL (FIRST_NAME) VALUES ('ALEXIS');

INSERT INTO TBL (FIRST_NAME) VALUES ('ANTHONY');

INSERT INTO TBL (FIRST_NAME) VALUES ('GERALD');

INSERT INTO TBL (FIRST_NAME) VALUES ('NANETTE');

INSERT INTO TBL (FIRST_NAME) VALUES ('JOHN');

INSERT INTO TBL (FIRST_NAME) VALUES ('KELLY');

INSERT INTO TBL (FIRST_NAME) VALUES ('KAREN');

INSERT INTO TBL (FIRST_NAME) VALUES ('CURTIS');

COMMIT;

SELECT * FROM TBL ;

FIRST_NAME         

-----------

Ellen

Sundar

Mozhe

David

Hermann

Shelli

Amit

Elizabeth

Sarah

David

Laura

Harrison

Alexis

Anthony

Gerald

Nanette

John

Kelly

Karen

Curtis

20 rows selected.

Need below output:

FIRST_NAME         

-----------

Mozhe

David

Amit

Elizabeth

Laura

Harrison

Gerald

Nanette

Karen

Curtis

Rule: Query should return 3rd & 4th row but next time counting should start from 4th rows. For example,

First 3rd row is : Mozhe

First 4th row is : David

Next 3rd row (start from 4th row) : Amit

Next 4th row (start from 4th row) : Elizabeth

Next 3rd row (start from 8th row) : Laura

Next 4th row (start from 8th row) : Harrison

and so on .

This post has been answered by KayK on May 8 2019
Jump to Answer
Comments
Post Details
Added on May 7 2019
9 comments
208 views