【发布时间】:2019-06-27 01:21:56
【问题描述】:
我需要创建一个报告,显示平均每天至少生产 30 件的员工
我有两张桌子:
Employees: id, name, surname
Production: id, date_time, id_employee, [..], quantity_produced
员工表中的 id = 生产表中的 id_employee
SELECT name, surname, Avg(quantity_produced), Month(data_ora) Mnth
FROM production inner join employees on employees.id = production.id_employee
GROUP BY name, quantity_produced, Month(date_time);
或
select name, surname, quantity_produced, avg(quantity_produced) as avgentrypermonth
from (
select month(date_time) as month ,count(1) as quantity
group by month(date_time));
或
select name, surname, quantity_produced
from production
inner join employees on employees.id = production.id_employee
where avg(quantity_produced) > 30;
【问题讨论】:
-
你需要对所有年份的所有月份进行 AVG 吗????
-
给定查询有什么问题?您能分享一下目前可行的方法以及您需要帮助的地方吗?
标签: mysql sql mysql-workbench