I have a SQL Query i.e.
SELECT
A2P.aid,
COUNT(*) [PaperCount],
[2010] = SUM(CASE WHEN A2P.p_year = 2010 THEN 1 ELSE 0 END),
[2011] = SUM(CASE WHEN A2P.p_year = 2011 THEN 1 ELSE 0 END),
[2012] = SUM(CASE WHEN A2P.p_year = 2012 THEN 1 ELSE 0 END),
[2013] = SUM(CASE WHEN A2P.p_year = 2013 THEN 1 ELSE 0 END),
[2014] = SUM(CASE WHEN A2P.p_year = 2014 THEN 1 ELSE 0 END)
FROM
sub_aminer_author2paper A2P
WHERE
aid IN (SELECT
aid
FROM
sub_aminer_author
WHERE
paper_count >= 20
)
AND A2P.p_year BETWEEN 2010 AND 2014
GROUP BY
A2P.aid
HAVING
COUNT(DISTINCT A2P.pid) >= 2
ORDER BY
A2P.aid
Now, the issue is I want to have rows in output containing value >= 2 in each column i.e. 2010
, 2011
, 2012
, 2013
, and 2014
OR the values in column Paper_Count
>= 10 for each row in output.
Moreover, I have used the condition as:
HAVING
COUNT(DISTINCT A2P.pid) >= 2
But results are not as desired. See the image for output...
As it is clear that 0
values are also retrieved in output which is not desired.
Please help in this regard.
Thanks!