Skip to content

Conversation

@vlnach
Copy link

@vlnach vlnach commented Sep 3, 2025

No description provided.

@yunchen4 yunchen4 self-assigned this Sep 5, 2025
Copy link

@yunchen4 yunchen4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just left some suggestions and possible blind spots.

Comment on lines +57 to +58
h_index SMALLINT CHECK (h_index >= 0),
gender TEXT CHECK (gender IN ('male','female','nonbinary','other'))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good use of SMALLINT for h_index here. For gender, you can also use SMALLINT as it is like enum. The disadvantage of using SMALLINT is that it is not so readable (when checking the table contents, people don't know 1 is female or male). But it is a common practice.

database: "research",
});

async function q(label, sql, params = []) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: have a better name for the function, so when reading the code we know what this function is for easily.

Comment on lines +39 to +49
await q(
"Total papers by female authors",
`SELECT SUM(cnt) AS total_papers_by_female
FROM (
SELECT a.author_id, COUNT(ap.paper_id) AS cnt
FROM authors a
LEFT JOIN author_papers ap ON ap.author_id = a.author_id
WHERE a.gender = 'female'
GROUP BY a.author_id
) x;`
);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: If a paper has two different female authors, this paper will be counted twice. Depending on the business requirements, this might be what we want. If you don't want to count the same paper twice, you need to change the query (use multiple JOIN instead of sub query).

Comment on lines +63 to +67
`SELECT a.university, COUNT(ap.paper_id) AS papers_sum
FROM authors a
LEFT JOIN author_papers ap ON ap.author_id = a.author_id
GROUP BY a.university
ORDER BY papers_sum DESC, a.university;`
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to the female author query, this will count the same paper twice if it has several authors from the same university.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants