I have a quiz game in which students have to solve questions from three categories like Chemistry, English, Physics. Students will score points in these categories like student1 has 50 in Chemistry, 70 in English and 65 in Physics.
I can figure out in which category a student has highest score. But how can I get something like which one is the highest score category any student have? I mean if a student got 90 points in English (No other student got this score), then how can we figure out this the top score of English is 90.
Remember: English score, Chemistry score, Physics score are data properties stored in rdf file. I want if it is possible using Jena rules or SPARQL or plain Java code.
If I understand you correctly, you're asking to find the maximum score in each category, and then to find, for each category, the student with that highest score in that category. It's easier to work with data (in the future, please try to provide minimal data that we can work with), so here's some sample data:
There are four categories, and student1 has the highest score in category1, student3 has the highest score in categories 2 and 4, and student2 has the highest score in category 3. We can write a query like this:
If you don't care about which student got the highest score, then you just want that inner subquery:
If you're using different properties
In a comment, you asked,
First, I'd recommend that you standardize your naming convention. First, be sure to use correct spelling (e.g., Physics). Then, either abbreviate or don't. You're abbreviating Chemistry to Chem, but not English to Eng. Finally, be consistent in your capitalization (e.g., EnglishScore, not Englishscore).
It's not necessary to use the kind of representation that I used. You didn't provide sample data (please do in the future), so I used what I considered a fairly easy one to use. Your representation seems a bit less flexible, but you can still get the information you want. Here's some new sample data:
Then the query just needs to use a variable for the property, and that variable simultaneously relates the student to the score, and also indicates the category. So you'd still just group by that property and ask for the highest score: