Could any one please help me with MySql database query:
I have one table with below data:
work_date   ticket no   category
------------------------------------
7/15/2013   111           a
7/15/2013   222           b
7/15/2013   333           c
7/16/2013   111           a
7/16/2013   555           e
7/16/2013   333           f
7/17/2013   111           H
I need help in writing a query which will read all table data, then create 2 columns one ticket no and second as category. Under ticket column it would show count of all distinct ticket number and value under category should be the last category assigned to that ticket.
i'm using the following query
SELECT category, count(distinct(ticket_no)) 
FROM master 
group by category 
order by 2 DESC`
the ticket which is present in 2 or more categories are being counted multiple times, I want it to be counted just once and that too the latest one
Expected Result:
Ticket No   Category
--------------------
111           H 
222           b 
333           f
555           e
 
     
     
     
     
    