需要sql查询

时间:2012-08-20 12:35:59

标签: sql postgresql

表格显示: showid, tutle, 链接 显示状态 运行 分类。
表格游戏: episodeid,showid,episodeNumber,seasonNumber,airDate,title。

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

2 个答案:

答案 0 :(得分: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

答案 1 :(得分: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