我有一个包含每个条目的表incident_id
,status
(假设是open
或closed
,date_raised
(日期)和closure_date
(日期)。
我想显示一个表格,计算在关闭日期关闭的事件数量(因此计数incident_id
where status='closed' and closure_date is not null
),以及保持打开的事件数量(在同一天的incident_id
where计数。status='open'
如果我把你弄糊涂了,一个看起来像这样的表:
______________________________________________________________________________
| closure date | count of incidents closed | count of incidents remaining open |
|--------------|---------------------------|-----------------------------------|
| 01-Sep-12 | 5 | 14 |
| ... | ... | ... |
我已经管理了一个表,它可以像这样计算关闭的事件数:
SELECT COUNT(incident_id)
WHERE closure_date IS NOT NULL AND status="open"
GROUP BY closure_date
我已经尝试了几个小时来让其他计数工作,但到目前为止还不能:-(
编辑:这是我拥有的表的示例:
___________________________________________________
| incident_id | status | date_raised | closure_date |
|-------------|--------|-------------|--------------|
| 1 | closed | 01-Sep-12 | 01-Sep-12 |
| 2 | open | 30-Aug-12 | (null) |
| 3 | open | 02-Sep-12 | (null) |
| 4 | closed | 02-Sep-12 | 05-Sep-12 |
| ... | ... | ... | ... |
会给桌子:
______________________________________________________________________________
| closure date | count of incidents closed | count of incidents remaining open |
|--------------|---------------------------|-----------------------------------|
| 01-Sep-12 | 1 | 1 |
| 05-Sep-12 | 1 | 2 |