开发者

get average of query result

开发者 https://www.devze.com 2023-01-23 14:47 出处:网络
Ive got query like this: select distinct UserID, Count(UserId) as MyNumber fromdbo.User2User gro开发者_如何学Cup by UserId

Ive got query like this:

select distinct UserID, Count(UserId) as MyNumber from  dbo.User2User gro开发者_如何学Cup by UserId

now I would like extend this query to get MIN, MAX and AVG of MyNumber

no idea how to get to this value from another select or sth ...

thanks for help


You can use your own query as a subquery :

SELECT MIN(MyNumber) AS minNumber, MAX(MyNumber) AS maxNumber, AVG(myNumber) AS avgNumber
FROM (SELECT UserID, COUNT(UserID) AS MyNumber
      FROM dbo.User2User
      GROUP BY UserID) TMP;

Note that the DISTINCT keyword isn't necessary : GROUP BY already selects distinct UserID.

0

精彩评论

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