Query for selecting individual names and counting names in sql

There are 2 columns in my table. Nameand Marks. Something like that.

Name         Marks
----------   -----------
AAA          50
BBB          48
CCC          54
AAA          52
DDD          55
BBB          60
AAA          66

I need to extract something like below from a table

Name       No.of.attempts    Max Mark
-------    ----------------  ------------
AAA         3                 66
BBB         2                 60
CCC         1                 54
DDD         1                 55
+4
source share
2 answers

You should do the following:

select name,count(name) as no_of_attempts,max(marks) 
from table_name 
group by name

fddle

+7
source

you can do it like that

 select name,COUNT(name) as nameCount,MAX(markes) as marks from #abc group by name
+2
source

All Articles