0

我目前在 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 服务器版本相对应的手册,以了解在 '[Rating] 附近使用正确的语法,COUNT( ) as 'total',CAST(count(*) 100.0/tot as decimal(12,1)) as ''在第 1 行

有人对将其翻译为 mysql 有任何建议吗?由于我的研究不足。提前致谢。

4

1 回答 1

0

我没有要尝试的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.tot
于 2013-05-13T11:53:09.397 回答