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 8390159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:54:46+00:00 2026-06-09T18:54:46+00:00

I have a student’s table with the following fields: student(student_id, student_name, student_avg) I need

  • 0

I have a student’s table with the following fields:

student(student_id, student_name, student_avg)

I need to write a query in MySQL which will display the result as :

Serial no. => the result should also have a new column with serial number as 1,2,3,...,n like an auto increment for each row in the result.

student_id
student_name
student_avg > 4

I don’t want to alter my table in any way. All I have to do is write a query which will give me the above result. I hope I am clear.

Example data:

student_id         student_name      student_avg 
 1                    abc               2.5
 2                    xyz               4.1
 3                    def               4.2     

Sample output after querying:

serial_no    student_id    student_name     student_avg
  1             2            xyz               4.1
  2             3            def               4.2
  • 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-09T18:54:47+00:00Added an answer on June 9, 2026 at 6:54 pm

    Try this on

    SELECT  @s:=@s+1 serial_number,student_id,student_name,student_avg
    FROM    students,
            (SELECT @s:= 0) AS s
    WHERE
    student_avg > 4;
    

    https://stackoverflow.com/a/11096550/1423506

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

Sidebar

Related Questions

i have table student,fields are student_id, student_name, year_joining ... now i want to rename
I am using SQL Server 2008. I have a Student table in which there
Possible Duplicate: MySQL dynamic cross tab I have student_record table ------------------------------------------------------------------- student_id | semester
I have a Student table which should have name column. But I made another
i have a table named students which have student details id,mark,name i want to
I need help writing a MySQL trigger. Suppose you have a student database with
I have a STUDENT table which contains data about students from a faculty: STUDENT(ID,
I have Class and Student objects. Both have collection of another as property. Which
I have a table student ( id, name ). Then I have one textbox,
I have a database Student which contains about 20 tables. one of the tables

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.