如何使用 count() 返回零值
如何返回 count(a.thread_id) = 0 的行?
SELECT current_date AS "Import Date",
b.container_id AS "ID",
b.name AS "Container Name",
b.creation_ts AS
"Container Creation Date",
COUNT(a.thread_id) AS
"Total Number of Un-Replied-To Threads",
round(Avg(current_date - ( 99 ) - a.creation_ts :: DATE)) AS "Average Age",
SUM(CASE
WHEN ( ( current_date - ( 99 ) - a.creation_ts :: DATE ) = 1 ) THEN
1
ELSE 0
END) AS "1 Day",
SUM(CASE
WHEN ( ( current_date - ( 99 ) - a.creation_ts :: DATE ) = 2 ) THEN
1
ELSE 0
END) AS "2 Day",
SUM(CASE
WHEN ( ( current_date - ( 99 ) - a.creation_ts :: DATE ) = 3 ) THEN
1
ELSE 0
END) AS "3 Day",
SUM(CASE
WHEN ( ( current_date - ( 99 ) - a.creation_ts :: DATE ) BETWEEN 4
AND 6 )
THEN 1
ELSE 0
END) AS "4-6 Days",
SUM(CASE
WHEN ( ( current_date - ( 99 ) - a.creation_ts :: DATE ) BETWEEN 7
AND 10
)
THEN 1
ELSE 0
END) AS "7-10 Days",
SUM(CASE
WHEN ( ( current_date - ( 99 ) - a.creation_ts :: DATE ) BETWEEN 11
AND 15
)
THEN 1
ELSE 0
END) AS "11-15 Days",
SUM(CASE
WHEN ( ( current_date - ( 99 ) - a.creation_ts :: DATE ) > 15 )
THEN 1
ELSE 0
END) AS "15+ Days"
FROM jivedw_message a,
jivedw_container b
WHERE a.thread_id IN (SELECT a.thread_id
FROM jivedw_message a
GROUP BY a.thread_id
HAVING COUNT(a.message_id) = 1)
AND a.thread_id NOT IN (SELECT a.thread_id
FROM jivedw_message a
INNER JOIN jivedw_object
ON ( jivedw_object.object_id =
a.thread_id )
INNER JOIN jivedw_activity_agg_user_day
ON (
jivedw_activity_agg_user_day.direct_dw_object_id =
jivedw_object.dw_object_id
)
WHERE jivedw_activity_agg_user_day.direct_object_type =
'1'
AND jivedw_activity_agg_user_day.activity_type IN
(30, 70)
)
AND ( a.container_id = b.container_id )
AND ( b.creation_ts > '2009-11-19' :: DATE )
GROUP BY b.container_id,
b.name,
b.creation_ts
ORDER BY b.name;
How can I return rows where count(a.thread_id) = 0?
SELECT current_date AS "Import Date",
b.container_id AS "ID",
b.name AS "Container Name",
b.creation_ts AS
"Container Creation Date",
COUNT(a.thread_id) AS
"Total Number of Un-Replied-To Threads",
round(Avg(current_date - ( 99 ) - a.creation_ts :: DATE)) AS "Average Age",
SUM(CASE
WHEN ( ( current_date - ( 99 ) - a.creation_ts :: DATE ) = 1 ) THEN
1
ELSE 0
END) AS "1 Day",
SUM(CASE
WHEN ( ( current_date - ( 99 ) - a.creation_ts :: DATE ) = 2 ) THEN
1
ELSE 0
END) AS "2 Day",
SUM(CASE
WHEN ( ( current_date - ( 99 ) - a.creation_ts :: DATE ) = 3 ) THEN
1
ELSE 0
END) AS "3 Day",
SUM(CASE
WHEN ( ( current_date - ( 99 ) - a.creation_ts :: DATE ) BETWEEN 4
AND 6 )
THEN 1
ELSE 0
END) AS "4-6 Days",
SUM(CASE
WHEN ( ( current_date - ( 99 ) - a.creation_ts :: DATE ) BETWEEN 7
AND 10
)
THEN 1
ELSE 0
END) AS "7-10 Days",
SUM(CASE
WHEN ( ( current_date - ( 99 ) - a.creation_ts :: DATE ) BETWEEN 11
AND 15
)
THEN 1
ELSE 0
END) AS "11-15 Days",
SUM(CASE
WHEN ( ( current_date - ( 99 ) - a.creation_ts :: DATE ) > 15 )
THEN 1
ELSE 0
END) AS "15+ Days"
FROM jivedw_message a,
jivedw_container b
WHERE a.thread_id IN (SELECT a.thread_id
FROM jivedw_message a
GROUP BY a.thread_id
HAVING COUNT(a.message_id) = 1)
AND a.thread_id NOT IN (SELECT a.thread_id
FROM jivedw_message a
INNER JOIN jivedw_object
ON ( jivedw_object.object_id =
a.thread_id )
INNER JOIN jivedw_activity_agg_user_day
ON (
jivedw_activity_agg_user_day.direct_dw_object_id =
jivedw_object.dw_object_id
)
WHERE jivedw_activity_agg_user_day.direct_object_type =
'1'
AND jivedw_activity_agg_user_day.activity_type IN
(30, 70)
)
AND ( a.container_id = b.container_id )
AND ( b.creation_ts > '2009-11-19' :: DATE )
GROUP BY b.container_id,
b.name,
b.creation_ts
ORDER BY b.name;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
点击谷歌并查找“Having”。在本例中,
count(a.thread_id) = 0
Hit up google and look up "Having". In this case,
having count(a.thread_id) = 0