I have a table as below.

Is it possible that I can make the output as above?
Thanks
I have a table as below.

Is it possible that I can make the output as above?
Thanks
 
    
     
    
    Here is the MYSQL Query to do that
SELECT id, date, msg, COUNT(id) AS count FROM table_name GROUP BY id
 
    
    Try following query:
SELECT t1.id, t1.date, t1.msg, t2.msg_count 
FROM table_name t1 
JOIN (SELECT max(msg_id) as mid, count(*) as msg_count FROM table_name GROUP BY id) as t2 
ON(t1.msg_id=t2.mid)
 
    
    Seems like you want latest date in the result set, so the query would look like something, SELECT id, max(date), msg, COUNT(id) AS count FROM table_name GROUP BY id
 
    
    For sql server, try this :
SELECT id, max(date) as date, msg, count(id) AS count 
FROM table_name 
GROUP BY id, msg
 
    
    SELECT T.id, Q.max_date, count(T.msg)
FROM Table1 T, (select id, MAX(dateD) as max_date from Table1 group by id) Q
where Q.id=T.id
group by T.id, Q.max_date
;
