Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. select c.*,read,lastUnread.action
  2. --,n.entity_id
  3. -- ,count(read) as unread_count,max(update_date)as last_update_date
  4. -- , lastUnread.action
  5. from cases c
  6. --inner join notification n on c.id = n.entity_id
  7. -- inner join user_notification un on n.id = un.notification_id
  8. --last unread
  9. left join (
  10. select * from (
  11. select notification_id, max(update_date) as dd from user_notification where read !=true group by notification_id order by dd desc limit 1) lastnotification
  12. inner join notification un on lastnotification.notification_id=un.id
  13. ) as lastUnread on c.id = lastUnread.entity_id
  14. -- read count
  15. left join (
  16. select entity_id,count(read) as read ,n.source_type from notification n inner join user_notification un on n.id = un.notification_id
  17. group by entity_id,read,n.source_type having read!=true and source_type=:sourceType
  18. ) as readCount on readCount.entity_id=c.id
  19.  
  20. --having read!=true and n.source_type='C' and c.id=:caseId
  21. group by c.id, read, lastUnread.action
  22. order by read asc;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement