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

Popular posts from this blog

GIT command

https://kbroman.org/github_tutorial/pages/branching.html Note:- Always get pull request before working on any branch git pull  branch name or  git pull  origin branch name To commit code git commit -m"comment for changes" To push the code git push origin staging To hold the branch in the same state git stash To get the stashed branch in normal mode git stash pop If code conflict during git command or reverting conflict occur while git pull or branch chekout git reset -hard HEAD To get in working branch or switch to another branch git checkout staging To create a new branch git checkout -b branch name