如何从两个表中选择最近的时间戳并按所述时间戳排序?
我当前的查询:
SELECT Series.*, Episodes.* FROM Series, Episodes
WHERE EpisodeAirDate > '.time().' AND Episodes.SeriesKey = Series.SerieID
GROUP BY Series.SerieTitle ORDER BY Episodes.EpisodeAirDate;
我想从 Episodes.EpisodeAirDate 最接近当前时间 (time()) 的 Episodes 中检索信息。这样我就得到了数据库中的最后一集。
我尝试过
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 和“时间直到”是正确的,但 EpisodeTitle、EpNo 和 SeasonNo 是第一个查询的内容。
真的很难解释。我希望你能明白这一点! :)
My current query:
SELECT Series.*, Episodes.* FROM Series, Episodes
WHERE EpisodeAirDate > '.time().' AND Episodes.SeriesKey = Series.SerieID
GROUP BY Series.SerieTitle ORDER BY Episodes.EpisodeAirDate;
I want to retrieve the information from Episodes where Episodes.EpisodeAirDate is the closest to the current time (time()). With this I just get the last episode in the database.
I've tried with
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;
which kind of works, but Episode.EpisodeTitle etc. does not correspond with the timestamp row.
Here I'm using the MIN()-query (http://grab.by/8UNY). I wasn't allowed to post an image, so perhaps a link will suffice :)
As you can see, the SerieTitle and "Time until" is correct, but the EpisodeTitle, EpNo and SeasonNo is that of the first query.
It's hard to explain, really. I hope you make sense of this! :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请尝试以下操作:
编辑:添加了 ORDER BY 子句。
Please try this:
Edit: Added the ORDER BY clause.