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

user5136052

For DB StudentInfo and Table Student as follows:

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

and inserting values:

Insert Into Student Values ('Ashok')` 

executing it 3 times, and

Insert Into Student Values ('Achyut')

executing it 2 times and total 5 rows of data are inserted into the 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 how to display the NoOfStudentHavingNameAshok & NoOfStudentHavingNameAchyut what query should I run?

sstan

You can put conditions inside your COUNT() function:

select count(case when Name = 'Ashok' then 'X' end) as NoOfStudentHavingNameAshok,
       count(case when Name = 'Achyut' then 'X' end) as NoOfStudentHavingNameAchyut
  from Student

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

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

From Dev

How to count different values in a same column in mysql?

From Dev

How do I use the SQL COUNT() function properly in this context?

From Dev

How do I use values as a column headers in a SQL Server Query

From Dev

How do I compare values from different column and different row but same table?

From Dev

How do I compare values from different column and different row but same table?

From Dev

Sql - How to count different column values grouped by another column

From Dev

How to count different values of records in same column for single id in MYSQL

From Dev

How to count different values of records in same column for single id in MYSQL

From Dev

How can I return two different values from the same column in a SQL Join?

From Dev

Count same values in different column mysql

From Dev

How to select count of different values in the corresponding column in SQL?

From Dev

How do I count instances of values in columns by individual column using only SQL?

From Dev

How can I count occurences of different integer values (in a particular column) for rows with different factor values(another column)?

From Dev

How to repeat the same SQL query for different column values

From Dev

How can i write sql code to bring values from another table and use count function?

From Dev

Using SQL how can I update field values of one column to match a different column's field value only if the values do NOT equal?

From Dev

How do I find the highest count of the same values with Pandas Python?

From Dev

How can I count different values stored in one cell in SQL?

From Dev

How do I count distinct combinations of column values?

From Dev

How do I count the number of nonzero values in a given array column?

From Dev

How do I calculate the sum of the values in a count column in mysql?

From Dev

SQL: How would I get a total count for distinct values in a column?

From Dev

How do I use a different query for a facet count

From Dev

How do I use a different query for a facet count

From Dev

How do I compare two different values of the same field in MySQL?

From Dev

How do I make a list of the same variable with different values? python

From Dev

sql joining on same column with different values

From Dev

How do I use MS Access SQL to make a not equal condition?

Related Related

  1. 1

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

  2. 2

    How to count different values in a same column in mysql?

  3. 3

    How do I use the SQL COUNT() function properly in this context?

  4. 4

    How do I use values as a column headers in a SQL Server Query

  5. 5

    How do I compare values from different column and different row but same table?

  6. 6

    How do I compare values from different column and different row but same table?

  7. 7

    Sql - How to count different column values grouped by another column

  8. 8

    How to count different values of records in same column for single id in MYSQL

  9. 9

    How to count different values of records in same column for single id in MYSQL

  10. 10

    How can I return two different values from the same column in a SQL Join?

  11. 11

    Count same values in different column mysql

  12. 12

    How to select count of different values in the corresponding column in SQL?

  13. 13

    How do I count instances of values in columns by individual column using only SQL?

  14. 14

    How can I count occurences of different integer values (in a particular column) for rows with different factor values(another column)?

  15. 15

    How to repeat the same SQL query for different column values

  16. 16

    How can i write sql code to bring values from another table and use count function?

  17. 17

    Using SQL how can I update field values of one column to match a different column's field value only if the values do NOT equal?

  18. 18

    How do I find the highest count of the same values with Pandas Python?

  19. 19

    How can I count different values stored in one cell in SQL?

  20. 20

    How do I count distinct combinations of column values?

  21. 21

    How do I count the number of nonzero values in a given array column?

  22. 22

    How do I calculate the sum of the values in a count column in mysql?

  23. 23

    SQL: How would I get a total count for distinct values in a column?

  24. 24

    How do I use a different query for a facet count

  25. 25

    How do I use a different query for a facet count

  26. 26

    How do I compare two different values of the same field in MySQL?

  27. 27

    How do I make a list of the same variable with different values? python

  28. 28

    sql joining on same column with different values

  29. 29

    How do I use MS Access SQL to make a not equal condition?

HotTag

Archive