Follow us on Social Media:

MySQL Database Administrator

Boost Your Quick Knowledge in MySQL DBA Work, Concepts, Tips and Trick

Thursday, 19 April 2018

Select Query to Print Rank on belalf of obtained Marks

​We have a test table as below..


Run below query to print rank...


SELECT id,  marks,
find_in_set(marks,(SELECT GROUP_CONCAT( distinct(marks) ORDER BY marks DESC ) FROM test )) AS rank
FROM test.test;

How to generate auto increment serial number column in MySQL Select Query / How to declear & pass variable in Select Query

In MySQL , We can generate auto increment serial number column during select query .

For e.g,

We have following table...


Using below queries , we can achieve the subjected discussion.


​SELECT @a:=@a+1 sr_num ,id,name,marks,insert_time from (select @a:=0) initvars, test.test;




Select all column :

SELECT @a:=@a+1 Sr_Num , A.* FROM (SELECT @A:= 0) initvars, test.test A ;

How to Select Nth highest marks/Value in Column ?

MySQL Select Query for Nth highest Value

​SELECT * from test.test where marks= (SELECT distinct (marks) FROM test.test order by marks desc limit (n-1),1);​

​We have following table..

Now we have to select 3rd highest Marks in table "test"

Query and it's result is showing below..

SELECT  * from test.test where marks= (SELECT distinct (marks) FROM test.test order by marks desc limit 2,1);


 
Please Like and Subscribe us ....

Please visit the website on daily basis , Your New articles will publish at any moment. Please Subscribe us for getting Latest Updates...