I am trying to run a query in SQL Server to loop through the associates and count how many transactions they processed.
select
Id, submitter_name, submitter_id,
count(*) as numberOfTickets
from
Tickets
where
created_at between '2018-11-13' and '2018-11-14'
and ',' + tags + ',' like '%,' + 'tickets' + ',%'
group by
Id, submitter_name, submitter_id;
This results shows the associates name over and over with one transaction. I am trying to count and show there name once with the total count for numberOfTickets.
I am not sure where I am going wrong here. Any help would be greatly appreciated!
WHEREclause',' + tags + ',' like '%,' + 'tickets' + ',%'very strongly suggests you're storing delimited data in your table. This is a really bad idea; I would strongly suggest redesigning your database to a more normalised format. (Or at least using a string splitter, and notLIKEwith a leading wild card, but a redesign would be a far better idea).COUNT(DISTINCT)?