Skip to content Skip to sidebar Skip to footer

How I Can Count Item In One Column With Sql Statement

I have one DB (programming is with Delphi) , and I want to count an item in one column. For example, the table like this: column1 | column2 -----------+------------- employee1

Solution 1:

A standard SQL aggregate that can be used in all database engines.

This gives "count per employee value"

SELECT
   column1, COUNT(*)
FROM
   MyTable
GROUPBY
   column1

For employee1 only

SELECTCOUNT(*)
FROM
   MyTable
WHERE
   column1 ='employee1'

Solution 2:

selectsum(
        casewhen column1 ='employee1'then1else0end
    )
fromtable;

Post a Comment for "How I Can Count Item In One Column With Sql Statement"