I am trying to put together a realtime view of users on our ticketing site.
Currently, I have 2 sessions on the site (Session col). My current query returns the following:
EVENTID EVENT Session SessionOpened SessionLength NumberofTix
1619 BB King 11 2013-01-28 09:34:16.300 -2 2
1622 BB King 12 2013-01-28 09:36:55.073 0 1
1622 BB King 12 2013-01-28 09:36:55.077 0 3
However, it should look like this :
EVENTID EVENT Session SessionOpened SessionLength NumberofTix
1619 BB King 11 2013-01-28 09:34:16.300 -2 2
1622 BB King 12 2013-01-28 09:36:55.073 0 4
Why is Session 12 returning 2 rows- 1 with 1 ticket and 1 with 3 tickets?
The query:
SELECT distinct set_eSRO_Event as EventID, shName as EventName, setSRO_UID as SRO_SessionID, setDateTime as SessionStarted,
DATEDIFF(mi, getDate(), setDateTime) as SessionTimer, Count(*) AS NumberofTickets FROM SessionTickets
INNER JOIN Shows on shCode = setShowCode
WHERE setStatus = 0
GROUP BY setsro_UID, shName, set_eSRO_Event, setDateTime
your result’s columns and query’s aliases are not coherent, so hard to say. I would imagine that setDateTime is different (= SessionStarted or SessionOpened). As you group by setDatetime, if they are different => two lines.
So add a
MINaggregate function to setDatetime (as in your “wanted” result), and remove setDatetime from GROUP BY