Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

select second largest amount from a table

Former Member
0 Likes
1,819

Hi All,

I want select second largest amount from a table . How i have to write a query for that?

Thanks,

Priya

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,195

You must write some extra logic for this:

data: begin of i_tbl occurs 0,

netwr like vbap-netwr,

end of i_tbl.

select netwr up to 2 rows from vbap into table i_tbl

order by netwr descending.

read table i_tbl index 2.

6 REPLIES 6
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,195

Well, I think you may need to get all of the data, then sort the amount column in descending order, then read line two of the internal table.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
1,195

You could:

SELECT * from table
  into itab.
sort itab descending by field1.
read table itab index 2.

Rob

You'll have to check the syntax. I didn't.

Message was edited by: Rob Burbank

Read only

Former Member
0 Likes
1,196

You must write some extra logic for this:

data: begin of i_tbl occurs 0,

netwr like vbap-netwr,

end of i_tbl.

select netwr up to 2 rows from vbap into table i_tbl

order by netwr descending.

read table i_tbl index 2.

Read only

0 Likes
1,195

John, I like that better. With the " up to 2 rows ". Nice.

Regards,

Rich Heilman

Read only

0 Likes
1,195

John - I like yours better.

Rob

Read only

0 Likes
1,195

Thank you, gentlemen.