Search for relevant rows and add rows according to timestamp

advertisements
Name       Count   Timestamp

'1FODC1IN', 5,  '2013-11-19 12:20:00'
'1FODC2IN', 6,  '2013-11-19 12:20:00'
'1FODC3IN', 42,  '2013-11-19 12:20:00'
'1FODC4IN', 34,  '2013-11-19 12:20:00'
'2FDCIN', 2,  '2013-11-19 12:20:00'
'2FISIN', 3,  '2013-11-19 12:20:00'
'2FODC1IN', 24, '2013-11-19 12:20:00'
'2FODC3IN', 4,  '2013-11-19 12:20:00'
'2FODC4IN', 6, '2013-11-19 12:20:00'
'CMNZ', 35,  '2013-11-19 12:20:00'
'GFAODCIN', 29,  '2013-11-19 12:20:00'
'MAINZN1', 111, '2013-11-19 12:20:00'

'1FODC1IN', 5,  '2013-11-20 11:50:13'
'1FODC2IN', 6,  '2013-11-20 11:50:13'
'1FODC3IN', 45,  '2013-11-20 11:50:13'
'1FODC4IN', 39,  '2013-11-20 11:50:13'
'2FISIN', 2, '2013-11-20 11:50:13'
'2FODC1IN', 20, '2013-11-20 11:50:13'
'2FODC3IN', 10,  '2013-11-20 11:50:13'
'2FODC4IN', 7, '2013-11-20 11:50:13'
'CMNZ', 39,  '2013-11-20 11:50:13'
'GFAODCIN', 23,  '2013-11-20 11:50:13'
'MAINZN1', 131, '2013-11-20 11:50:13'

This kind of data is getting logged in every 15 min interval .

My requirement is to find the 'IN' word in the name and add up all the 1F%IN occurring together , similarly 2F%IN together , GF%IN together and so on .

Need the output as

Name  count  timestamp

first  87    2013-11-19 12:20:00
Second 39    2013-11-19 12:20:00
ground 29    2013-11-19 12:20:00
first  87    2013-11-20 11:50:13
Second 39    2013-11-20 11:50:13
ground 29    2013-11-20 11:50:13

Adding based on timestamp is also very important .

How can I do this .


SQLFiddle demo

SELECT GName,
       SUM(`Count`),
       `Timestamp`
FROM
(
select
     CASE WHEN Name LIKE '1F%IN' THEN 'first'
          WHEN Name LIKE '2F%IN' THEN 'second'
          WHEN Name LIKE 'GF%IN' THEN 'ground'
          ELSE 'Unknown'
     END as GName,
     `Count`,
     `Timestamp`
FROM T
  WHERE Name LIKE '%IN'
) T1
Group by GName,`Timestamp`
order by `Timestamp`,GName