2

经过一些帮助,请:)

以下 MySQL 查询

select id, customer_id, user,
(((q_responce_time + o_responce_time + cs_responce_time + q_accuracy + 
o_accuracy + cs_accuracy + q_personnel + o_personnel + cs_personnel + 
q_communication + o_communication + d_communication + cs_communication + 
q_overall + qu_overall + o_overall + d_overall + cs_overall + profile + 
glass + parts + roof + in_full + direct_delivery + damages + service)/125)*100) as total,
month(create_datetime) as posted_month 
from cs_review_centre
Where
create_datetime >= '2013-01-01' 
and create_datetime < '2013-10-31'
and customer_id = 26
order by posted_month, customer_id

产生以下结果

"customer_id"  | "user"     |"total"    |"posted_month"|
"26"           | "co2_test" |"72.8000"  |   "7"        |
"26"           | "co2_test" |"60.8000"  |   "8"        |
"26"           | "Lisa"     |"81.6000"  |   "9"        |
"26"           | "Lisa"     |"84.0000"  |   "10"       |
"26"           | "Lisa"     |"52.0000"  |   "10"       |

我想要实现的是当一个posted_month 包含一个重复值时我想平均“总”

任何帮助将不胜感激

谢谢

4

2 回答 2

0

Just GROUP BY customer_id, user,posted_month and use AVG() function

select customer_id, user,
AVG(
(((q_responce_time + o_responce_time + cs_responce_time + q_accuracy + 
o_accuracy + cs_accuracy + q_personnel + o_personnel + cs_personnel + 
q_communication + o_communication + d_communication + cs_communication + 
q_overall + qu_overall + o_overall + d_overall + cs_overall + profile + 
glass + parts + roof + in_full + direct_delivery + damages + service)/125)*100)
) as AverageTotal,
month(create_datetime) as posted_month 
from cs_review_centre
Where
create_datetime >= '2013-01-01' 
and create_datetime < '2013-10-31'
and customer_id = 26

GROUP BY customer_id, user,posted_month 

order by posted_month, customer_id
于 2013-10-30T11:11:46.823 回答
0

Try:

select id, customer_id, user,
avg((((q_responce_time + o_responce_time + cs_responce_time + q_accuracy + 
o_accuracy + cs_accuracy + q_personnel + o_personnel + cs_personnel + 
q_communication + o_communication + d_communication + cs_communication + 
q_overall + qu_overall + o_overall + d_overall + cs_overall + profile + 
glass + parts + roof + in_full + direct_delivery + damages + service)/125)*100)) as total,
month(create_datetime) as posted_month 
from cs_review_centre
Where
create_datetime >= '2013-01-01' 
and create_datetime < '2013-10-31'
and customer_id = 26
group by id, customer_id, user, month(create_datetime)
order by posted_month, customer_id
于 2013-10-30T11:12:34.693 回答