使用字符串文本“1:”前置整数结果以创建比率

时间:2015-02-05 21:53:06

标签: sql concat

以下查询返回单个数字,表示n 1:N比率。1:。我不是只返回一个数字,而是如何使用以下文本select round((sum (case when unified_rollup_level_1 = "Company A" and person_type = "Employee" and worker_status = "Active" then 1 else 0 end)) / (sum (case when unified_rollup_level_1 = "Company A" and person_type = "Employee" and worker_status = "Active" and job_level IN ("08", "09") then 1 else 0 end)),0) 添加整数值,以便为结果提供正确的比率格式?

{{1}}

2 个答案:

答案 0 :(得分:0)

假设它适用于MySQL:

select 
    CONCAT("1:", round((sum (case when unified_rollup_level_1 = "Company A" 
                          and person_type = "Employee" 
                          and worker_status = "Active" 
                then 1 
                else 0 
                end)) /
                (sum (case when unified_rollup_level_1 = "Company A" 
                                and person_type = "Employee" 
                                and worker_status = "Active" 
                                and job_level IN ("08", "09") 
                            then 1 
                             else 0 
                      end)),0))

我希望它有所帮助。

答案 1 :(得分:0)

您只需执行以下操作即可添加文字:

SELECT "Foo" + stuff FROM table;

在这种情况下,如果东西是3,结果将是" Foo3" (没有引号)。

所以在你的情况下:

SELECT "1:" + ... -- the rest of it goes here