1

我的查询按优先级计算 SLA 内的呼叫总数。但是现在我需要在同一个语句中按优先级计算出 SLA 内的呼叫百分比

但是我不确定如何在我当前的声明中执行此操作

`SELECT
 SUM(o.withinfix) 'Total'
 ,o.priority 'priority'
 FROM opencall o
 WHERE LEFT(FROM_UNIXTIME(o.logdatex),4) = "2013"
 AND o.fk_company_id = "abc"
 GROUP BY o.priority'

谁能帮忙,我用的是MYSQL 5.1

谢谢

4

2 回答 2

1
 SELECT SUM(o.withinfix) 'Total',
        SUM(o.withinfix) / (select SUM(withinfix) from opencall) * 100 as perc
        o.priority 'priority'
 FROM opencall o
 WHERE LEFT(FROM_UNIXTIME(o.logdatex),4) = "2013"
 AND o.fk_company_id = "abc"
 GROUP BY o.priority
于 2013-07-31T10:33:25.090 回答
0

您可以只使用总计的子选择来做到这一点:

SELECT SUM(o.withinfix) 'Total' ,o.priority 'priority',
    (SELECT SUM(withinfix) FROM opencall AS o2 GROUP BY o2.priority) AS sum_total
FROM opencall o
WHERE LEFT(FROM_UNIXTIME(o.logdatex),4) = "2013"
AND o.fk_company_id = "abc" GROUP BY o.priority'

并在查询后手动计算百分比。

于 2013-07-31T10:42:25.627 回答