2

table shows: showid, tutle, link show status runtime classification.
table episdes: episodeid, showid, episodeNumber,seasonNumber,airDate,title.

Hello, i need sql query to select title serial and count episodes which already released(edisodes.airDate - date release episode) please help me) thanks who help.

2 Answers 2

2
select  s.title
,       s.serial
,       e.title
,       sum(case when e.airDate <= current_timestamp then 1 end) 
            over (partition by s.title, s.serial)
from    shows s
left join
        episodes e
on      e.showid = s.showid
        and e.airDate <= current_timestamp
Sign up to request clarification or add additional context in comments.

2 Comments

its display only one show and total for all released episodes. i need a query which select all shows in table shows and total released episodes like e.showid = s.showid
Ok, changed to return all shows, and the number of released shows using a window function
1

Sub query could be used there. E.g.

select s.title, s.serial, e.count
from shows s, (select showId, count(*) as count 
                from episodes 
                where airDate <= current_timestamp
                group by showId) e
where s.showId == e.showId

3 Comments

This would return one row per show? Didn't you comment that you're looking for all episodes per show?
Its return all show and count released episodes current show.
If that's what you're after, consider accepting the answer (the green V below the vote buttons, to the left of the answer)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.