Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- select
- u.id as UserID,
- u.DisplayName,
- u.Username,
- u.Capacity as Capacity,
- count(cq.chatid) as ActiveChats,
- case when count(cq.chatid) >= u.Capacity then 1 else 0 end as AtCapacity
- from
- users u
- left join
- ChatQueueItems cq
- on
- cq.UserID = u.ID
- left join
- Chats c
- on
- c.ID = cq.ChatID
- and
- c.[Status] in (0,1) -- 0 = awaiting pickup, 1 = active
- where
- u.[online] = 1
- group by
- u.id,
- u.DisplayName,
- u.Username,
- u.capacity
Add Comment
Please, Sign In to add comment