Mysql 更改选择结果的布局

Mysql 更改选择结果的布局,mysql,Mysql,我有下面的查询,我想更改结果的显示方式。我研究过如何使用枢轴,但我不知道如何使用枢轴,如果能得到帮助,我将不胜感激 (缩短的)查询: 我想将数据显示为: descr | per_sec | percent | offered under_5_sec | 346 | 91.7772 | 87.3737 under_10_sec| 353 | 93.6340 | 89.1414 有什么建议可以实现吗?选择 select 'under_5_se

我有下面的查询,我想更改结果的显示方式。我研究过如何使用枢轴,但我不知道如何使用枢轴,如果能得到帮助,我将不胜感激

(缩短的)查询:

我想将数据显示为:

descr       | per_sec   | percent   | offered
under_5_sec | 346       | 91.7772   | 87.3737
under_10_sec| 353       | 93.6340   | 89.1414
有什么建议可以实现吗?

选择
select 
 'under_5_sec' as descr,
 count(if(verb in ('COMPLETEAGENT','COMPLETECALLER') and queue in (9100, 9102, 9104) and data1 <= 5,1, null)) as per_sec,
 count(if(verb in ('COMPLETEAGENT','COMPLETECALLER') and queue in (9100, 9102, 9104) and data1 <= 5,1, null)) / COUNT(if(verb in ('COMPLETEAGENT','COMPLETECALLER') and queue in (9100, 9102, 9104, 9106, 9108, 9600, 9602, 9500, 9502, 9800, 9802),1, null)) * 100 as perct,
 count(if(verb in ('COMPLETEAGENT','COMPLETECALLER') and queue in (9100, 9102, 9104) and data1 <= 5,1, null)) / COUNT(if(verb in ('ENTERQUEUE') and queue in (9100, 9102, 9104, 9106, 9108, 9600, 9602, 9500, 9502, 9800, 9802),1, null)) * 100 as offer,
from queue_log
where partition = 'P001'
and time_id >= unix_timestamp('2016-10-30') and time_id < unix_timestamp('2016-10-31')
UNION
select 
 'under_10_sec' as descr,
 count(if(verb in ('COMPLETEAGENT','COMPLETECALLER') and queue in (9100, 9102, 9104) and data1 <= 10,1, null)) as per_sec,
 count(if(verb in ('COMPLETEAGENT','COMPLETECALLER') and queue in (9100, 9102, 9104) and data1 <= 10,1, null)) / COUNT(if(verb in ('COMPLETEAGENT','COMPLETECALLER') and queue in (9100, 9102, 9104, 9106, 9108, 9600, 9602, 9500, 9502, 9800, 9802),1, null)) * 100 as perct,
 count(if(verb in ('COMPLETEAGENT','COMPLETECALLER') and queue in (9100, 9102, 9104) and data1 <= 10,1, null)) / COUNT(if(verb in ('ENTERQUEUE') and queue in (9100, 9102, 9104, 9106, 9108, 9600, 9602, 9500, 9502, 9800, 9802),1, null)) * 100 as offer
from queue_log
where partition = 'P001'
and time_id >= unix_timestamp('2016-10-30') and time_id < unix_timestamp('2016-10-31')
“5秒以下”作为描述,
count(if)(动词in('COMPLETEAGENT','COMPLETECALLER')和queue in(9100,9102,9104)以及data1可能重复的感谢,这确实给了我想要的结果。像这样使用union是否运行两次查询(每个union)?这种结果需要联合。我不知道mysql的内部结构。但我认为每个记录对查询求值一次,而不是两次。我的意思是表记录不会一个接一个地与两个查询进行比较。联合创建两个数据集,然后“联合”以形成一个查询结果。感谢T Gray。Stephen您还可以使用union all而不是union来避免两个集合的比较。
descr       | per_sec   | percent   | offered
under_5_sec | 346       | 91.7772   | 87.3737
under_10_sec| 353       | 93.6340   | 89.1414
select 
 'under_5_sec' as descr,
 count(if(verb in ('COMPLETEAGENT','COMPLETECALLER') and queue in (9100, 9102, 9104) and data1 <= 5,1, null)) as per_sec,
 count(if(verb in ('COMPLETEAGENT','COMPLETECALLER') and queue in (9100, 9102, 9104) and data1 <= 5,1, null)) / COUNT(if(verb in ('COMPLETEAGENT','COMPLETECALLER') and queue in (9100, 9102, 9104, 9106, 9108, 9600, 9602, 9500, 9502, 9800, 9802),1, null)) * 100 as perct,
 count(if(verb in ('COMPLETEAGENT','COMPLETECALLER') and queue in (9100, 9102, 9104) and data1 <= 5,1, null)) / COUNT(if(verb in ('ENTERQUEUE') and queue in (9100, 9102, 9104, 9106, 9108, 9600, 9602, 9500, 9502, 9800, 9802),1, null)) * 100 as offer,
from queue_log
where partition = 'P001'
and time_id >= unix_timestamp('2016-10-30') and time_id < unix_timestamp('2016-10-31')
UNION
select 
 'under_10_sec' as descr,
 count(if(verb in ('COMPLETEAGENT','COMPLETECALLER') and queue in (9100, 9102, 9104) and data1 <= 10,1, null)) as per_sec,
 count(if(verb in ('COMPLETEAGENT','COMPLETECALLER') and queue in (9100, 9102, 9104) and data1 <= 10,1, null)) / COUNT(if(verb in ('COMPLETEAGENT','COMPLETECALLER') and queue in (9100, 9102, 9104, 9106, 9108, 9600, 9602, 9500, 9502, 9800, 9802),1, null)) * 100 as perct,
 count(if(verb in ('COMPLETEAGENT','COMPLETECALLER') and queue in (9100, 9102, 9104) and data1 <= 10,1, null)) / COUNT(if(verb in ('ENTERQUEUE') and queue in (9100, 9102, 9104, 9106, 9108, 9600, 9602, 9500, 9502, 9800, 9802),1, null)) * 100 as offer
from queue_log
where partition = 'P001'
and time_id >= unix_timestamp('2016-10-30') and time_id < unix_timestamp('2016-10-31')