I am currently working with an audit log table similar to:
ID | EventTime | AccessID | AccessType | Status | Final
------------------------------------------------------------------------------
1 | 2013/02/10 01:01:01 | NULL | 123 | 335 | OK
2 | 2013/02/10 01:01:01 | 985521 | NULL | 66 | OK
....
41 | 2013/02/10 07:07:07 | NULL | 456 | 335 | OK
42 | 2013/02/10 07:07:07 | 113228 | NULL | 66 | OK
What I need to select is the AccessID
and AccessType
into one row, i.e.:
AccessID | AccessType
------------------------
985521 | 123
113228 | 456
The AccessID
is always unique and are only available in the row where Status = 66
. The AccessType
is only available where the Status = 335
.
The EventTime
is always shared for status 335 and 66.
I have tried grouping the data by event time, using sub selects etc but haven't quite managed to get the end result I need.
Additional Info
There are approximately 100000 rows a day added. For each EventTime there are approximately 40 rows all with different information (there are more columns than the example provided below)
Try this way:
select max(AccessID) as AccessID, max(AccessType) as AccessType
from audit_log
where Status in (335,66)
group by EventTime
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With