日期:2014-05-18  浏览次数:20737 次

求高人!!!
怎么样才查出哪些行参与了平均数计算?

平均数的计算方法是:(先算的是a的并且在范围内的平均值,b是比例,然后是统计)
SQL code

SELECT  [name], 
AVG(a) as a, 
SUM(CASE WHEN b<=5 THEN 1 ELSE 0 END) * 100.0 / COUNT(b) AS b
FROM  ta
GROUP BY name
having 
AVG(a)>'1'

UNION ALL 
SELECT  '统计', 
AVG(a) as a,
AVG(b) as b
FROM(
SELECT  [name], 
AVG(a) as a, 
SUM(CASE WHEN b<=5 THEN 1 ELSE 0 END) * 100.0 / COUNT(b) AS b
FROM  ta
GROUP BY name
having 
AVG(a)>'1'
)ta



数据库是:数据随意

name a b


------解决方案--------------------
那些行是什么意思?

满足条件的行都参加了啊

SQL code
select * from ta
where name in
(
SELECT  [name]
FROM  ta
GROUP BY name
having 
AVG(a)>1
)