A database table contains 3
fields(Student_no,Section,Total_marks).I want retrieve top 10
students from each section.Note:(Section contains data like
A,B,C.Each section contains more than 10 students).
Answers were Sorted based on User's Feedback
Answer / anonymous
Those mark the answer as No. pls provide the right answer
Is This Answer Correct ? | 1 Yes | 0 No |
Answer / sivaramakrishna
according to our requirment
get allthe records using select * from st_db into stu_itab1.
1.first sort the stu_itab1 by marks field.
now use the select single section from st_db into stu_itab2.
now we have to use select for all entries as below.
select section marks from stu_itab1 into table stu_itab3
for all entries in stu_itab2 upto 10 rows.
it may be not exact . but do try in this way
Is This Answer Correct ? | 2 Yes | 1 No |
Answer / waseem
**Sorry guys for above wrong code which I posted, You can **use this code with 100 % result****
tables : ywt_student, ywt_result.
data : begin OF itab OCCURS 0, "structure from 2 tables
usn like ywt_student-usn,
name like ywt_student-name,
dob like ywt_student-dob,
cls like ywt_result-class,
marks like ywt_result-marks,
end of itab.
**"selecing values from 2 tables*****
select ywt_student~usn name dob class marks
INTO TABLE itab
from ywt_student INNER JOIN ywt_result on ywt_student~usn = ywt_result~usn.
**Sorting for testing Perpose*****
sort itab by cls ASCENDING marks DESCENDING.
LOOP AT itab.
on CHANGE OF itab-cls.
skip.
ENDon.
WRITE :/ itab-usn, itab-name, itab-dob, itab-cls, itab-marks.
ENDLOOP.
skip 2.
***Actual Logic of Requirement***
data : m LIKE ywt_result-marks.
data : count TYPE i value 0.
CLEAR itab.
sort itab by cls ASCENDING marks DESCENDING.
CLEAR itab.
LOOP AT itab.
m = itab-marks.
on CHANGE OF itab-cls.
skip 2.
count = 0.
ENDon.
AT NEW cls.
itab-marks = m.
count = count + 1.
IF count LE 10.
WRITE :/ itab-usn, itab-name, itab-dob, itab-cls, itab-marks.
CLEAR itab.
ENDIF.
ENDAT.
ENDLOOP.
Is This Answer Correct ? | 1 Yes | 0 No |
Answer / shaheen
This can be achived by '...group by' addition in the select
statement.
Regards,
Shaheen
Is This Answer Correct ? | 2 Yes | 2 No |
Answer / sateesh
for this initially we can SORT in assending order,
then using "select up to 10 rows".
Is This Answer Correct ? | 2 Yes | 2 No |
Answer / waseem
DATA itab LIKE zabc OCCURS 10 WITH HEADER LINE.
SELECT * FROM zbad5 INTO TABLE itab.
SORT itab BY sclass smarks.
data : count type i value 0.
LOOP AT itab.
AT NEW sclass.
count = count + 1.
IF ( count LE 10 ).
WRITE: / itab."-sno1, itab-sclass, itab-smarks.
ENDIF.
ENDAT.
AT END of sclass.
count = 0.
ENDAT.
ENDLOOP.
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / balamurugan
REPORT zscenario.
DATA itab LIKE zabc OCCURS 10 WITH HEADER LINE.
SELECT * FROM zbad5 INTO TABLE itab.
SORT itab BY sclass smarks.
LOOP AT itab.
AT NEW sclass.
WRITE: / itab."-sno1 itab-sclass itab-smarks.
ENDAT.
This display the report based upon the class.But i don't know how to retrieve 10 records from each class.
ENDLOOP.
Is This Answer Correct ? | 0 Yes | 2 No |
In the function module for reading text from the S.O header what needs to be specified?
How to handle errors in call transaction bdc method without using bdcmsgcoll internal table? : abap bdc
What are smart forms?
Difference between /N and /BEND?
how to fill the select options from an internal table dynamically ie can i use the loop in the initialization
What are the basic functions of database utility?
What is Implicit and explicit enhancements.
what is data class?
What data is contained in data dictionary? : abap data dictionary
What is macro? : abap hr
Define dispatcher?
what is difference between commit and rollback.?