On 3/7/2016 9:47 PM, Stephen Chrzanowski wrote:
> Currently my application makes two queries to the database.  One to get the
> list of projects via [ select ProjectID,Description from Projects order by
> Description ]
>
> It then goes through each record retrieved and then gets another query via
> [ select (select count(VideoID) from vViewedVideos where DateViewed is null
> and ProjectID=:P) Unwatched, (select count(VideoID) from vViewedVideos
> where ProjectID=:P) Videos ] where :P is the ProjectID.


select ProjectID, Description,
   sum(VideoID is not null and DateViewed is null) Unwatched,
   count(VideoID) Videos
from Projects left join vViewedVideos using (ProjectID)
group by ProjectID;

-- 
Igor Tandetnik

Reply via email to