使用两个计数功能 [英] using two count function
本文介绍了使用两个计数功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
我正在尝试在存储过程的一个select语句中使用两个count函数,但是不起作用
Hi
I am trying to use two count function in one select statement in stored procedure but doesn''t works
SELECT DISTINCT COUNT(order),count(Cus),name
FROM MEd inner join Portfolios on MEd .MEd ID = Port.MEd Ref
INNER JOIN Pro on Port.portID = Pro.portRef
INNER JOIN P on Pro.proID = P.proRef
WHERE Port.MEd = @ID
GROUP BY name
推荐答案
您好
检查此
Hi
Check this
SELECT DISTINCT COUNT([order]),count(Cus),name
FROM MEd inner join Portfolios on MEd .MEd ID = Port.MEd Ref
INNER JOIN Pro on Port.portID = Pro.portRef
INNER JOIN P on Pro.proID = P.proRef
WHERE Port.MEd = @ID
GROUP BY name
最好的问候
M.Mitwalli
Best Regards
M.Mitwalli
有几个问题:
DISTINCT
关键字错误,将其删除.
如果列名包含空格,则必须使用[方括号]来转义"该名称,例如[MEd Ref]
.
请勿在表名和列名之间添加空格,例如用MEd.[MEd ID]
代替MEd .MEd ID
!
ORDER
是保留字,必须转义.
我建议给COUNT列命名,例如
SELECT COUNT([order]) as OrderCount, COUNT(Cus) as CusCount, name
There are several issues:
TheDISTINCT
key word is wrong, remove it.
If a column name contains blanks, you have to "escape" that name by using [square brackets], e.g.[MEd Ref]
.
Do not add blanks between table name and column name, e.g. useMEd.[MEd ID]
instead ofMEd .MEd ID
!
ORDER
is a reserved word and must be escaped.
I suggest to give the COUNT columns names, e.g.
SELECT COUNT([order]) as OrderCount, COUNT(Cus) as CusCount, name
这篇关于使用两个计数功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文