【问题标题】:tsql query not working in mysqltsql查询在mysql中不起作用
【发布时间】:2013-05-07 09:21:24
【问题描述】:

我目前在 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)) 作为 '' 在第 1 行

有没有人有任何关于把它翻译成 mysql 的建议?由于我的研究不足。提前致谢。

【问题讨论】:

    标签: mysql tsql casting partitioning


    【解决方案1】:

    我没有要尝试的 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
    

    【讨论】:

      猜你喜欢
      • 2012-04-08
      • 2017-02-23
      • 2014-09-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-12
      • 1970-01-01
      相关资源
      最近更新 更多