I have 2 data tables I need to query data from
Machine_ID Machine_name
101 Computer1
202 Computer2
303 Computer3
404 Computer4
Second table:
Machine_ID Event_ID Event_date
101 1 03/15/2016
101 1 03/14/2016
101 2 03/15/2016
101 1 03/13/2016
102 1 03/15/2016
102 2 03/15/2016
102 1 03/14/2016
103 2 03/15/2016
103 2 03/14/2016
104 1 03/15/2016
I need the output of the query to be in one line and contain information:
Machine_ID,
Machine_Name,
Count(Machine_ID) where Event_ID='1'
Count(Machine_ID) where Event_ID='2'
I have tried numerous ways to write the query but am at a loss for the correct syntax.
This does not work but will give an idea of what I'm going for:
Select M.Machine_ID, M.Machine_Name,
count(Machine_ID) where E.Event_ID='1' and Machine_ID='101',
count(Machine_ID) where E.Event_ID='2' and Machine_ID='101'
from Machines M
join Events E on M.Machine_ID = E.Machine_ID
The output from this based in the given data should be:
101 Computer1 3 1