Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9128591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:33:04+00:00 2026-06-17T07:33:04+00:00

I have a mysql table like: Sample Data ID STUDENT_ID Branch_id Class_id Exam_id Subject_id

  • 0

I have a mysql table like:

Sample Data


ID  STUDENT_ID  Branch_id   Class_id    Exam_id Subject_id  Numbers     Date
1       653         5           1           1   8               60      2012-01-01
2       653         5           1           1   9               40      2012-01-01
3       653         5           1           1   10              80      2012-01-01
4       653         5           1           1   11              50      2012-01-01
5       653         5           1           1   12              65      2012-01-01
6       653         5           1           1   13              33      2012-01-01
7       653         5           1           1   15              86      2012-01-01
8       222         5           1           1   8               100     2012-01-01
9       222         5           1           1   9               80      2012-01-01
10      222         5           1           1   10              92      2012-01-01
11      222         5           1           1   11              50      2012-01-01
12      222         5           1           1   12              65      2012-01-01
13      222         5           1           1   13              33      2012-01-01
7       222         5           1           1   15              86      2012-01-01

I need to get rank of student in class even if there two student are equal in marks. example if two students get 600 marks out of 600 marks that means both are on first position.

I search many site and I found this post that works what I need but in this post the correct column already sum of marks but in my table I need to sum(numbers) then get rank of of student depend on there total marks.

This all when I fetched the result of single student.

At same data when I fetched result for all class there is two thing needs. First row to column pivot query that display result in excel format so I use row to colum query like:

SELECT m.* 
FROM (
   select student_id, branch_id, class_id, numbers,  exam_id, date
        , sum(numbers*(1-abs(sign(subject_id-1)))) as subs1
        , sum(numbers*(1-abs(sign(subject_id-2)))) as subs2
        , sum(numbers*(1-abs(sign(subject_id-3)))) as subs3
        , sum(numbers*(1-abs(sign(subject_id-4)))) as subs4
        , sum(numbers*(1-abs(sign(subject_id-5)))) as subs5
        , sum(numbers*(1-abs(sign(subject_id-6)))) as subs6 
   from results 
   GROUP BY student_id, branch_id, class_id,  exam_id
   ) m 
where branch_id = '6' 
 and class_id = '1' 
 and exam_id = '1' 
 and YEAR(date) = '2013' 

Required Result In class query like:


ID      Name        Math        English     Science     Total   Percent     Position    Rank

And I got result fine by this query. but still there is problem in rank how to get rank of students in same query?

Can any one help?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T07:33:05+00:00Added an answer on June 17, 2026 at 7:33 am

    My Questin is that how to use SUM(numbers) instead of correct because in the post query the correct answer already sumed.

    Select from a subquery instead of a table.

    Second …

    I don’t fully understand your second question, and don’t see the relation to the first. Please write separate posts to ask separate questions.

    sum(numbers*(1-abs(sign(subject_id-1))))
    

    You can write this as sum(numbers*(subject_id = 1)) as MySQL uses 0 for false and 1 for true when evaluating a boolean operation like this comparison.

    One more note: it would be better in terms of performance to move the WHERE conditions inside the subquery m.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a MySql table with sample data like this: +---------+---------+--------+---------------------+ | id |
I have a MySQL table like this: Payments +----+---------------------+---------+ | id | date (sorted
I have these two table with some data sample in them. I would like
I have a mysql table , which holds data like this. Name |how_out |runs
i have the following mysql tables with some sample data. 1) table: ai_shipment +----+---------------------+---------------------+------------------+
I have a MySQL table like so; foo bar 1 21 23 17 31
I have a MySQL table like id | text | category | active I
I currently have a MySQL table like: id | friend 1 | 2 1
I have a mysql table structure like that: id int primary key name varchar
I have a MySQL table looking like this: > describe books; +---------------+--------------+------+-----+---------+----------------+ | Field

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.