I've 2 tables, Paper and Author. Paper contains all the papers published in a given time period and Authors has the name of author in one column and id of paper published in another(so, the same author may occur several times). Now I'm supposed to find the average number of authors per paper.
My try:-
(SELECT COUNT(*) FROM Author as decimal)/(SELECT COUNT(*) FROM Paper);
Clearly the first part will give me the number of rows in table Author and the second gives me the total no. of papers published. But, I'm getting an error "ERROR: syntax error at or near "/"". What I believe is that it's because I'm probably dividing a table by a table(since I'm just a beginner in postgres, I may be horribly wrong, please correct me if that's the case). I just wanna know how can we solve this error. Thanks!
Assuming all papers have at least one author:
select count(*) * 1.0 / count(distinct paper_id)
from authors;
The * 1.0
is to avoid integer division.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With