我有一个问题,
SELECT E.staffid AS staff
SUM(E.Frequency= Less ) AS lessCount,
SUM(E.Frequency= More ) AS moreCount,
FROM effort_frequency E
INNER JOIN ost_staff S ON S.staff_id = E.staffid
WHERE E.log_date BETWEEN 2012-05-01 AND 2012-05-23
GROUP BY E.staffid
我得到了下面的桌子,
+-------+-----------+-----------+
| Staff | lessCount | moreCount |
+-------+-----------+-----------+
| 1 | 2 | 3 |
| 3 | 1 | 4 |
| 5 | 2 | 3 |
+-------+-----------+-----------+
您可以看到结果中缺少 2 & amp; 4 。 在给定日期的 < code> effort_ danger code> 表格中, 将会有 < em> no 列 em>, 有 staff_ id 2 & amp; 4 。 但我正在尝试加入 < code> ost_ staff code> 表格, 这样我就可以得到像下表一样的东西 。 ost_ staff 将包含所有的工作人员 ID, 例如 1-5 。
+-------+-----------+-----------+
| Staff | lessCount | moreCount |
+-------+-----------+-----------+
| 1 | 2 | 3 |
| 2 | 0 | 0 |
| 3 | 1 | 4 |
| 4 | 0 | 0 |
| 5 | 2 | 3 |
+-------+-----------+-----------+
我尝试了外缘组合 但它不工作, 我想我做错了某处。