如何使用SQL语句在一个列中计数项目 [英] How i can count item in one column with SQL statement

查看:295
本文介绍了如何使用SQL语句在一个列中计数项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个DB(使用Delphi编程),并且我想在一列中计数一个项目。

I have one DB (programming is with Delphi) , and I want to count an item in one column.

例如, p>

For example, the table like this:

column1    | column2
-----------+-------------
employee1  | employee2
employee3  | employee1
employee1  | employee1
employee2  | employee3

我想计算那些列中的员工,例如, $

I want to count employees in that columns, for example, how i can get result 2, from count( employee1) in column1?

推荐答案

可在所有数据库引擎中使用的标准SQL聚合。

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

给出每个员工价值的计数

This gives "count per employee value"

SELECT
   column1, COUNT(*)
FROM
   MyTable
GROUP BY
   column1

仅适用于employee1

For employee1 only

SELECT
   COUNT(*)
FROM
   MyTable
WHERE
   column1 = 'employee1'

这篇关于如何使用SQL语句在一个列中计数项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆