Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- select c.*,read,lastUnread.action
- --,n.entity_id
- -- ,count(read) as unread_count,max(update_date)as last_update_date
- -- , lastUnread.action
- from cases c
- --inner join notification n on c.id = n.entity_id
- -- inner join user_notification un on n.id = un.notification_id
- --last unread
- left join (
- select * from (
- 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
- inner join notification un on lastnotification.notification_id=un.id
- ) as lastUnread on c.id = lastUnread.entity_id
- -- read count
- left join (
- select entity_id,count(read) as read ,n.source_type from notification n inner join user_notification un on n.id = un.notification_id
- group by entity_id,read,n.source_type having read!=true and source_type=:sourceType
- ) as readCount on readCount.entity_id=c.id
- --having read!=true and n.source_type='C' and c.id=:caseId
- group by c.id, read, lastUnread.action
- order by read asc;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement