SELECT
recipient_status."noticeId",
COUNT(1) AS "recipientCount",
NVL(SUM(recipient_status."received"), 0)
AS "receivedCount",
NVL(SUM(recipient_status."read"), 0)
AS "readerCount",
MIN(recipient_status."receivedTime")
AS "firstReceivedTime"
FROM (
SELECT
recipient."通告编号" AS "noticeId",
recipient."用户编号" AS "accountId",
MAX(
CASE
WHEN recipient."已接收" = 1 THEN 1
ELSE 0
END
) AS "received",
MAX(
CASE
WHEN recipient."已阅读" = 1 THEN 1
ELSE 0
END
) AS "read",
MIN(
CASE
WHEN recipient."已接收" = 1
THEN recipient."接收时间"
ELSE NULL
END
) AS "receivedTime"
FROM "通告用户信息" recipient
GROUP BY
recipient."通告编号",
recipient."用户编号"
) recipient_status
GROUP BY recipient_status."noticeId"
AND LOWER(notice."标题") LIKE
'%' || LOWER(#{query.title}) || '%'
AND notice."类别" = #{query.category}
AND NVL(statistics."firstReceivedTime",
notice."发布时间")
>= #{query.sendStartTime}
AND NVL(statistics."firstReceivedTime",
notice."发布时间")
<= #{query.sendEndTime}
AND statistics."recipientCount" > 0
AND statistics."receivedCount"
= statistics."recipientCount"
AND statistics."receivedCount" > 0
AND statistics."receivedCount"
< statistics."recipientCount"
AND statistics."receivedCount" = 0