目前,以下脚本在TSQL中运行良好:
select v.ratings as [Rating], COUNT(*) as 'total',
CAST(count(*)*100.0/tot as decimal(12,1)) as 'percent'
from (select (case when Ratings = 5 then '5'
when Ratings = 6 then '6'
when Ratings = 7 then '7'
end) as Ratings,
COUNT(*) over (partition by NULL) as tot
from vHighPerformance) v
group by v.Ratings, v.tot这个脚本在MYSQL中不起作用。它给出了以下内容: 1064 -您的SQL语法有一个错误;请检查与您的MySQL服务器版本对应的手册,以获得正确的语法,以便在第1行使用接近“评级、计数()为”总计“、强制转换(计数(*)100.0/tot为十进制(12,1)”的语法。
有没有人对把这个翻译成mysql有什么建议?因为我的研究还不够。提前谢谢。
发布于 2013-05-13 11:53:09
我没有一个mysql安装可以尝试,但这应该是可行的:
select v.ratings as Rating, COUNT(*) as total,
CAST(count(*)*100.0/tot as decimal(12,1)) as percent
from (select (case when Ratings = 5 then '5'
when Ratings = 6 then '6'
when Ratings = 7 then '7'
end) as Ratings,
(SELECT COUNT(*) FRMO vHighPerformance) as tot
from vHighPerformance) v
group by v.Ratings, v.tothttps://stackoverflow.com/questions/16520407
复制相似问题