Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Hi, I've got an sql query issue (MS-SQL)I have a table with 3 columnsthe table looks like this:TicketID TicketHolder TicketCounter1 Joe 41 Tom 23 Joe 1as you can see, each ticket ID might be listed under more than one ticket holderwhoever has the largest TicketCounter is considered to be that TicketID's ownerI want to run a query which will bring how many tickets are held by each person (if they hold any of course)I ran this query but it's bringing me also non ticket owners - any ideas ?select TicketHolder, COUNT(TicketID) as TicketsOwned from Tickets group by TicketHolder
my problem is that the query doesn't take into account ticket ownership ... it lists Joe correctly with 2 tickets owned by him , but also provides a false account of 1 ticket held by Tom
Under Ticket ID 1 you have two ticket holders:joe who's counter is 4and tom who's counter is 2since joe's counter is higher he is considered to be the ticket owner(the ticket with the ID of 1)what I want to do is to summerize how many tickets are OWNED per person, and I'm sure my query is wrong :)any ideas on what should be the correct query ?