Skip to main content

condition with order by clause in query - postgresql

SELECT count(main.id) as count,main.status, (sum(count(main.id)) over ()) as total FROM Tickets main 
JOIN Groups Groups_1 ON ( LOWER(Groups_1.Domain) = 'rt::ticket-role' ) AND ( LOWER(Groups_1.Name) = 'requestor' ) 
AND (Groups_1.Instance = main.id ) JOIN CachedGroupMembers CachedGroupMembers_2  ON (CachedGroupMembers_2.Disabled = '0') 
AND ( CachedGroupMembers_2.GroupId = Groups_1.id ) JOIN Users Users_3  ON ( Users_3.id = CachedGroupMembers_2.MemberId ) 
JOIN queues queues_3 ON ( main.queue = queues_3.id) JOIN users users_4 ON ( main.owner = users_4.id ) WHERE (main.IsMerged IS NULL) 
AND (main.Status != 'deleted') AND (main.Type = 'ticket') 
and main.created::timestamp AT time zone 'utc'>='2017-11-20 23:06:06'  
and main.queue in (5,6,7,8) and main.created::timestamp AT time zone 'utc'<='2018-07-11 06:14:26' 
and main.status!='open' and main.status!='assigned' and main.status!='rejected' 
and main.status in ('new','in-progress','resolved') 
group by main.status 

order by case when main.status ='new' then 1 when main.status= 'in-progress' then 2 when main.status ='resolved' then 3 end asc

Comments