0

I need some help here, I'm sure you guys know how to do it: Let's start with table structure:

author(name, nationality, Gender);
article(title, year, conference);
publication(articleTitle, authorName);

I need to know the Gender of authors which have the highest number of publications. By the Way I'm using PostgreSQL, don't know if that matters.

Here's My idea:

select gender from author
join publication on(name = authorName)
having (count(articleTitle) = max(count(articleTitle)))
group by gender

Now, I know i cannot use nested aggregate functions, and that's why I'm trying to use nested selects, something like select gender where gender in (another select) But I did not managed to avoid the aggregate function issue. Hope you can help me, Thank you

1
  • Sample data and desired results would help. Commented May 31, 2018 at 10:53

1 Answer 1

1

This query gets you the authors, ordered by the number of publications:

select a.name, a.gender, count(*) as num_publications
from author a join
     publication p
     on a.name = p.authorName
group by a.name, a.gender
order by num_publications desc;

If you want the top three, then use fetch first or limit:

select a.name, a.gender, count(*) as num_publications
from author a join
     publication p
     on a.name = p.authorName
group by a.name, a.gender
order by num_publications desc
fetch first 3 rows only;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.