SQL - count relation instances -
i have sql diagram:
i want subscribers likes 0 reports.
started by: select * subscriber having count(...)
how count how many reporters subscriber likes?
a relationship should it's own table in sql database?
i'm not sure understand last question, sounds nice time not in
clause.
select * subscriber id not in (select subscriberid likes inner join reporter on reporter.id = likes.reporterid)
the inner query there finds subscriber ids have been reported, outer 1 grabs other ones. might able improve efficiency of query changing inner join
in
, you'd have play it.
as far task of counting them, i'd this. group , such, simple,
select *, (select count(*) likes inner join reporter on reporter.id = likes.reporterid likes.subscriberid = subscriber.id) reporterscount subscriber
note listed task of finding ones 0 reporters, first query faster, because able short-circuit, rather having count every reporter every row. of course, neither should bad long you've got appropriate indexes.
Comments
Post a Comment