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 構文にエラーがあります。 Near '[Rating], COUNT( ) as 'total', CAST(count(*) 100.0/tot as decimal(12,1)) as ''を使用する正しい構文については、MySQL サーバーのバージョンに対応するマニュアルを確認してください。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 に答える