我当前的查询:
SELECT Series.*, Episodes.* FROM Series, Episodes
WHERE EpisodeAirDate > '.time().' AND Episodes.SeriesKey = Series.SerieID
GROUP BY Series.SerieTitle ORDER BY Episodes.EpisodeAirDate;
我想从Episodes中检索Episodes.EpisodeAirDate最接近当前时间(time())的信息。有了这个我就得到了数据库中的最后一集。
我试过
SELECT Series.*, Episodes.*, MIN(Episodes.EpisodeAirDate) AS EpisodeAirDate FROM Series, Episodes
WHERE EpisodeAirDate > '.time().' AND Episodes.SeriesKey = Series.SerieID
GROUP BY Series.SerieTitle ORDER BY EpisodeAirDate;
哪种作品,但Episode.EpisodeTitle等与时间戳行不对应。
这里我使用的是MIN() - 查询(http://grab.by/8UNY)。我不被允许发布图像,所以也许链接就足够了:)
正如你所看到的,SerieTitle和“Time until”是正确的,但EpisodeTitle,EpNo和SeasonNo是第一个查询。
真的很难解释。我希望你理解这一点! :)
答案 0 :(得分:1)
请试试这个:
SELECT S.*,E.* FROM Series S
JOIN (SELECT SeriesKey, MIN(EpisodeAirDate) MinDate FROM Episodes
WHERE EpisodeAirDate > NOW() GROUP BY SeriesKey) M
ON M.SeriesKey = S.SerieID
JOIN Episodes E ON E.SeriesKey = S.SerieID AND E.EpisodeAirDate = M.MinDate
ORDER BY E.EpisodeAirDate;
编辑:添加了ORDER BY子句。