gorgon2k Posted November 16, 2010 Share Posted November 16, 2010 OK here's what i need to do. I have a table of tickets for a tech company. they want a report that shows how many ticket each tech has in order of most to least. so say there's 12 tech. the query(s) need to be able to take each individual tech, output their amount of tickets and sort them in order of most tickets. how would I go about this. Any idea? Quote Link to comment https://forums.phpfreaks.com/topic/218856-tricky-conecept-can-it-be-done/ Share on other sites More sharing options...
ManiacDan Posted November 16, 2010 Share Posted November 16, 2010 SELECT tech.name, COUNT(ticket.id) FROM tech JOIN ticket ON ticket.tech_id = tech.id WHERE ticket.state = 'open' GROUP BY tech.name ORDER BY COUNT(ticket.id) DESC Adjust for your tables and fields and whatnot. -Dan Quote Link to comment https://forums.phpfreaks.com/topic/218856-tricky-conecept-can-it-be-done/#findComment-1135022 Share on other sites More sharing options...
gorgon2k Posted November 16, 2010 Author Share Posted November 16, 2010 dan, thanks for the help. It seems that you have two seperate tables in your query.. all this info is contained in one... it's structured like Name Ticket Id Bob D 98678 Bob D 43256 Bob D 534534 Jim B 098098 Jim B 654675465 Mike T 5345gfd So basically i'd need to get an output like Bob D 3 Jim B 2 Mike T 1 Quote Link to comment https://forums.phpfreaks.com/topic/218856-tricky-conecept-can-it-be-done/#findComment-1135038 Share on other sites More sharing options...
mikosiko Posted November 16, 2010 Share Posted November 16, 2010 same ... just with one table.... however... what Dan is suggesting in term of using 2 tables is the right way that you should design your DB Quote Link to comment https://forums.phpfreaks.com/topic/218856-tricky-conecept-can-it-be-done/#findComment-1135050 Share on other sites More sharing options...
ignace Posted November 16, 2010 Share Posted November 16, 2010 SELECT name, count(*) FROM tickets GROUP BY name Quote Link to comment https://forums.phpfreaks.com/topic/218856-tricky-conecept-can-it-be-done/#findComment-1135115 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.