开发者

Sql query syntax problem.(system.data.sqlserverce)

Can any one please suggest me whats the wrong with my query.

SELECT SUM(cCallDuration), COUNT(*), AVG(cCallduration), 
       cBeginTime, cEndTime, cAnswerTime, cCallDuration, cDispatcherName, cConsoleName,
       cEndpointName, cProfileName, cC开发者_开发问答allDirection, cCallType,
       cCallNature, cCallData, cDirectedCall
FROM  CALLINFO 
WHERE cBeginTime >='7/11/2011 12:00:00 AM' 
     AND cEndTime <='7/11/2011 12:00:00 AM' 
     AND cCallType='InBound' 
GROUP BY cConsoleName

I'm getting this error:

In aggregate and grouping expressions, the SELECT clause can contain only aggregates and grouping expressions. [ Select clause = ,cBeginTime ]


You have to have more in your GROUP BY clause

Check out this example. Every column that is not aggregate is included in the GROUP BY. You must do that also

SELECT Customer,OrderDate,SUM(OrderPrice) FROM Orders
GROUP BY Customer,OrderDate

Try this one:

SELECT SUM(cCallDuration), COUNT(*), AVG(cCallduration), 
       cDispatcherName, cConsoleName,              
FROM  CALLINFO 
WHERE cBeginTime >='7/11/2011 12:00:00 AM' 
     AND cEndTime <='7/11/2011 12:00:00 AM' 
     AND cCallType='InBound' GROUP BY cConsoleName,cDispatcherName

so to complete your full sql syntax you have to include every column that is not an aggregate in your GROUP BY clause and that means every column except the SUM,AVG and COUNT


GROUP BY clause : Columns in any nonaggregate expression in the SELECT list must be included in the GROUP BY list.

SELECT SUM(cCallDuration), COUNT(*), AVG(cCallduration), 
       cBeginTime, cEndTime, cAnswerTime, cCallDuration, cDispatcherName, cConsoleName,
       cEndpointName, cProfileName, cCallDirection, cCallType,
       cCallNature, cCallData, cDirectedCall
FROM  CALLINFO 
WHERE cBeginTime >='7/11/2011 12:00:00 AM' 
     AND cEndTime <='7/11/2011 12:00:00 AM' 
     AND cCallType='InBound' GROUP BY 
        cBeginTime, cEndTime, cAnswerTime, cCallDuration, cDispatcherName, cConsoleName,
       cEndpointName, cProfileName, cCallDirection, cCallType,
       cCallNature, cCallData, cDirectedCall
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜