如何在sql server中从我的表中计算客户? [英] How can i count customer from my table in sql server?

查看:66
本文介绍了如何在sql server中从我的表中计算客户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有1张桌子(销售客户)。此表包含客户信息和发票信息。
2013年6月
,此表有550行,如果是i区客户,则有5个客户。

我想要数每个客户。例如:客户他买了多少发票,客户B他买了多少发票.......那么有谁知道我可以为每个客户算什么?



谢谢



TONY

Hi all experts,
i have 1 table (Sales Customer). This table contains customer info and invoice info.
in June 2013, this table has 550 lines and if i district customer, it has 5 customers.
I want to count for each customer. Ex: Customer A how many invoices he bought, Customer B How many invoices he bought.......So Does anybody know how i can count for each customers?

Thanks

TONY

推荐答案

试试这个:

Try this:
SELECT COUNT(1) AS InvCount
FROM CustomerSales
GROUP BY CustomerID


你可以使用group by子句。



从tblname中选择count(columnname)

group by columnname



Ex。



通过EMPID从员工组中选择计数(empid)
you can use group by clause.

Select count(columnname) from tblname
group by columnname

Ex.

select count(empid) from Employee group by EMPID


这篇关于如何在sql server中从我的表中计算客户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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