Sql 在整数结果前面加上字符串文本“quot;1:";创造比率

Sql 在整数结果前面加上字符串文本“quot;1:";创造比率,sql,concat,Sql,Concat,下面的查询返回一个数字,以1:n比率表示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 =

下面的查询返回一个数字,以
1:n
比率表示
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)

假设它是针对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))

我希望它能有所帮助。

您可以通过以下操作预先编写文本:

SELECT "Foo" + stuff FROM table;
在本例中,如果stuff是3,则结果将是“Foo3”(不带引号)

因此,在你的情况下:

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

谢谢所以,我遇到的问题是串接字符串文本+整数的问题。由于这个原因,脚本每次都失败了。必须首先将整数转换为字符串,使用instr和left函数删除小数(因为在转换为字符串时由于某种原因舍入函数被忽略),然后将带引号的文本与新转换的字符串文本“number”连接起来。