All pastes #2068628 Raw Edit

funkytuba

public text v1 · immutable
#2068628 ·published 2011-05-24 20:04 UTC
rendered paste body
select count(distinct publisher.publisher_id) as num_publishers, count(distinct book.publisher_id) as num_publishers_with_books
from publisher left join book on publisher.publisher_id = book.book_id


or two separate statements:

select count(*) from publishers

select count(distinct publisher_id) from book


counting with CASE:

select count(synopsis_id) num_synopses, count(review_id) num_reviews,
sum(case when (synopsis_id is not null and review_id is not null) then 1 else 0 end) num_both,
sum(case when (synopsis_id is null and review_id is null) then 1 else 0 end) num_neither
 from book