2

表格显示:showid、tutle、链接显示状态运行时分类。
表剧集:episodeid,showid,episodeNumber,seasonNumber,airDate,title。

您好,我需要 sql 查询来选择标题序列并计算已经发布的剧集(edisodes.airDate - 发布日期剧集)请帮助我)谢谢谁的帮助。

4

2 回答 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
于 2012-08-20T12:38:23.333 回答
1

可以在那里使用子查询。例如

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
于 2012-08-20T13:23:59.550 回答