繁体   English   中英

那么如何通过计算在表上添加一列

[英]so how to add a column on table with calculating

我做了一个查询,结果如下:

select claim_by, count(*) as total_response, 
       count (response_time > minute (response_time -30)) as total_target,
       count(response_time > minute (response_time +30)) as total_untarget,
       (COUNT(claim_by)/alltotal) * 100 AS percentage_total_response
from itcorp_first_response,
     (SELECT COUNT(claim_by) AS alltotal 
      FROM itcorp_first_response) AS alltotal
GROUP BY claim_by;

在此处输入图片说明

那么如何在查询中添加一个计算 total_target/total_response * 100 的列..?

尝试子查询

select *,(total_target/total_response) as [total_target/total_response] from
(
select 
claim_by, 
count(*) as total_response, 
       count (response_time > minute (response_time -30)) as total_target,
       count(response_time > minute (response_time +30)) as total_untarget,
       (COUNT(claim_by)/alltotal) * 100 AS percentage_total_response
from itcorp_first_response,
     (SELECT COUNT(claim_by) AS alltotal 
      FROM itcorp_first_response) AS alltotal
GROUP BY claim_by
)XX

你只需要写出来:

select claim_by, count(*) as total_response, 
       count (response_time > minute (response_time -30)) as total_target,
       count(response_time > minute (response_time +30)) as total_untarget,
       (COUNT(claim_by)/alltotal) * 100 AS percentage_total_response,
       count (response_time > minute (response_time -30)) / count(*) *100
from itcorp_first_response,
     (SELECT COUNT(claim_by) AS alltotal 
      FROM itcorp_first_response) AS alltotal
GROUP BY claim_by;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM