日期:2014-05-18 浏览次数:20614 次
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
select * from tb where name in( select name 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' 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 )t )
------解决方案--------------------
把AVG去掉就行了
------解决方案--------------------
去掉所有avg就可以了