0

我有四个查询,每个查询有 6 列。除了 WHERE 子句在每种情况下略有不同之外,每个查询都是相同的。我想看到的是彼此相邻的每一列的每个查询结果以进行比较。

示例结果表标题:时间(只有一个),calls1,calls2,calls3,calls4,work1,work2,work3,work4,tele1,tele2,tele3,tele4,comm1,comm2,comm3,comm4,techs1,techs2,techs3,techs4 .

实际查询如下。请帮我做一个比较查询。吨

SELECT CONCAT(hour(opened_dt),':',floor(minute(opened_dt)/15)*15) AS time, COUNT(*)/COUNT(DISTINCT DATE(opened_dt)) AS r_calls, ROUND(AVG(work_time),2)/60 AS r_work, ROUND(AVG(tele_time),2)/60 AS r_tele, ROUND(AVG(comm_time),2)/60 AS r_comm, IFNULL(COUNT(*)/COUNT(DISTINCT DATE(opened_dt)),0)/3 AS r_techs 
FROM detail_head LEFT JOIN detail_detail ON detail_detail.detail_head_uid = detail_head.detail_head_uid 
WHERE call_origins_uid != 5 
AND DATE(opened_dt) >= (CURDATE() - INTERVAL 42 DAY) 
AND dayname(opened_dt) = 'SUNDAY' 
GROUP BY (hour(opened_dt)*100)+floor(minute(opened_dt)/15) 


SELECT CONCAT(hour(opened_dt),':',floor(minute(opened_dt)/15)*15) AS time, COUNT(*)/COUNT(DISTINCT DATE(opened_dt)) AS calls, ROUND(AVG(work_time),2)/60 AS work, ROUND(AVG(tele_time),2)/60 AS tele, ROUND(AVG(comm_time),2)/60 AS comm, IFNULL(COUNT(*)/COUNT(DISTINCT DATE(opened_dt)),0)/3 AS techs 
FROM detail_head LEFT JOIN detail_detail ON detail_detail.detail_head_uid = detail_head.detail_head_uid 
WHERE call_origins_uid != 5 
AND DATE(opened_dt) >= (CURDATE() - INTERVAL 42 DAY) 
AND dayname(opened_dt) = 'SUNDAY' 
AND call_origins_uid = 1 
GROUP BY (hour(opened_dt)*100)+floor(minute(opened_dt)/15)


SELECT CONCAT(hour(opened_dt),':',floor(minute(opened_dt)/15)*15) AS time, COUNT(*)/COUNT(DISTINCT DATE(opened_dt)) AS calls, ROUND(AVG(work_time),2)/60 AS work, ROUND(AVG(tele_time),2)/60 AS tele, ROUND(AVG(comm_time),2)/60 AS comm, IFNULL(COUNT(*)/COUNT(DISTINCT DATE(opened_dt)),0)/3 AS techs 
FROM detail_head LEFT JOIN detail_detail ON detail_detail.detail_head_uid = detail_head.detail_head_uid 
WHERE call_origins_uid != 5 
AND DATE(opened_dt) >= (CURDATE() - INTERVAL 42 DAY) 
AND dayname(opened_dt) = 'SUNDAY' 
AND call_origins_uid = 4 
GROUP BY (hour(opened_dt)*100)+floor(minute(opened_dt)/15)


SELECT CONCAT(hour(opened_dt),':',floor(minute(opened_dt)/15)*15) AS time, COUNT(*)/COUNT(DISTINCT DATE(opened_dt)) AS calls, ROUND(AVG(work_time),2)/60 AS work, ROUND(AVG(tele_time),2)/60 AS tele, ROUND(AVG(comm_time),2)/60 AS comm, IFNULL(COUNT(*)/COUNT(DISTINCT DATE(opened_dt)),0)/3 AS techs 
FROM detail_head LEFT JOIN detail_detail ON detail_detail.detail_head_uid = detail_head.detail_head_uid 
WHERE DATE(opened_dt) >= (CURDATE() - INTERVAL 42 DAY) 
AND dayname(opened_dt) = 'SUNDAY' 
GROUP BY (hour(opened_dt)*100)+floor(minute(opened_dt)/15)
4

1 回答 1

1

您可以为每个表使用“CREATE TEMPORARY TABLE TableName1”,然后编写一个查询以按顺序排列列,然后在完成后删除表。

于 2013-06-18T17:35:20.977 回答