reject_data
+-----------+-----------------+------------------+---------------+
| reject_id | reject_location | reject_equipment | reject_time |
+-----------+-----------------+------------------+---------------+
| 1 | 7 | 6 | 1326795921000 |
+-----------+-----------------+------------------+---------------+
| 2 | 7 | 1 | 1326796641000 |
+-----------+-----------------+------------------+---------------+
| 3 | 7 | 6 | 1326799521000 |
+-----------+-----------------+------------------+---------------+
| 4 | 6 | 5 | 1326800781000 |
+-----------+-----------------+------------------+---------------+
| 5 | 7 | 3 | 1326802281000 |
+-----------+-----------------+------------------+---------------+
| 6 | 7 | 4 | 1326802941000 |
+-----------+-----------------+------------------+---------------+
| 7 | 7 | 1 | 1326814161000 |
+-----------+-----------------+------------------+---------------+
| 8 | 6 | 2 | 1328026700000 |
+-----------+-----------------+------------------+---------------+
設備
+--------------+------------------+
| equipment_id | equipment_string |
+--------------+------------------+
| 1 | Microdoser |
+--------------+------------------+
| 2 | Monoblock |
+--------------+------------------+
| 3 | Valve Magnet |
+--------------+------------------+
| 4 | Checkweigher |
+--------------+------------------+
| 5 | Microleak |
+--------------+------------------+
| 6 | Capper |
+--------------+------------------+
查詢
SELECT equipment_string AS eqpt, COUNT(reject_id) AS cnt
FROM reject_data
RIGHT OUTER JOIN equipment ON (reject_equipment = equipment_id)
WHERE reject_location IN (1,2,7) AND equipment_id IN (1,2,3,4,5,6) AND reject_time BETWEEN 1329479810000 AND 1329483410000
GROUP BY equipment_id
ORDER BY cnt DESC
問題
如何更改我的查詢以便它還返回零計數的設備?很堅持:(
感謝您的幫助
注:動態變量填充在正常
+1您先寫下了它!人們首先測試你的查詢。 – rcdmk 2012-02-17 15:06:36
當我正確理解OP時,那些過濾器是期望的行爲。 – Kaii 2012-02-17 15:07:28
@Kaii:對不起,你*沒有*正確理解OP。他/她想「也返回[]具有零計數的設備」。 – ruakh 2012-02-17 15:11:05