jeudi 24 septembre 2015

How Can I Use Count Function for the different values of the same column in MS-SQL?

I have created a Database StudentInfo and a table named Student as follows:

    CREATE TABLE Student(
ID INT PRIMARY KEY IDENTITY(1,1),
Name nvarchar(255)
)

and inserting the values: Insert Into Student Values ('Ashok') Executing it 3 times and Insert Into Student Values ('Achyut')Executing it 2 times and total 5 data are inserted into table. I want to display a result counting the result with the Name Having 'Ashok' & 'Achyut'.

Generally for Single Values Count in a column i use: SELECT Count(Name) as NoOfStudentHavingNameAshok From Student WHERE Name='Ashok'

but to dispaly the NoOfStudentHavingNameAshok & NoOfStudentHavingNameAchyut what query should i run?

Aucun commentaire:

Enregistrer un commentaire