我有这两个表:
var areaCalc = function(x,y) {
this.x = x ;
this.y = y ;
}
areaCalc .prototype = {
area: function() { return (this.x * this.y); }
}
//var newarea = new areaCalc (5,23);
function onObjectWithPrototype () {
areaCalc(2,3);
alert(areaCalc.prototype.area());
//alert(newarea .area());
}
和:
customer
id
name
created_at
我想获得action
id
customer_id
type
created_at
和customer.created_at
之间的平均时间差,其中action.created_at
和操作是第一个条目(操作可能有很多action.type = "call0"
)
现在,我有这个查询:
type = "call0"
不知道为什么,此查询返回几行-每行用于输入操作。
如何返回整个平均值计算?
答案 0 :(得分:0)
如果您希望获得总结果,则不要按customer.id分组
SELECT AVG(TIME_TO_SEC(timediff(action.created_at, customer.created_at)) / 60) AS diff
FROM action
JOIN customer ON action.customer_id = customer.id
WHERE action.type = "call0"
否则,如果您要为每个customer.id求平均值,请尝试同时显示相应的customer.id
SELECT customer.id, AVG(TIME_TO_SEC(timediff(action.created_at, customer.created_at)) /60) AS diff
FROM action
JOIN customer ON action.customer_id = customer.id
WHERE action.type = "call0"
GROUP BY customer.id
ORDER BY action.created_at ASC