需要算法建议:对电视节目剧集进行排序的最佳方式是什么?

发布于 2024-12-05 03:36:23 字数 393 浏览 0 评论 0原文

我有一个包含各种电视节目剧集的 Sqlite 数据库,我想按它们的“新鲜度”(即它们的季节和剧集编号)对它们进行升序和降序排序。

例如:

  • 第 1 季第 1 集
  • 第 1 季第 2 集
  • [...]
  • 第 2 季第 1 集

... 或反之亦然:

  • 第 2 季第 2 集
  • 第 2季第 2 集1
  • [...]
  • 第 1 季第 2 集

我已将数据库中每个条目的季数和集数存储为两个不同的变量,因此可以基于此执行某些操作。

您对如何以最优化的方式完成它有什么建议吗?

I've got a Sqlite database with various TV show episodes, and I'd like to sort them ascending and descending by their "freshness", i.e. their season and episode number.

For example:

  • Season 1 Episode 1
  • Season 1 Episode 2
  • [...]
  • Season 2 Episode 1

... or the other way around:

  • Season 2 Episode 2
  • Season 2 Episode 1
  • [...]
  • Season 1 Episode 2

I've got the season and episode numbers stored as two different variables for each entry in the database, so it's possible to do something based on that.

Do you have any suggestions as to how it can be done in the most optimal way possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

尾戒 2024-12-12 03:36:23

你只是要求一个sql语句吗?
在这种情况下,考虑到您提到了 2 个单独的变量,我们分别将它们称为“季节”和剧集,您可以执行以下操作:

升序: select * from Shows order by season asc, Episode asc

降序:从节目顺序中选择*,按季节描述,剧集描述

“最佳”,至少从性能的角度来看,将把两个变量组合成第三个变量(如果你需要)。称之为“episodeOrder”。

“episodeOrder”必须首先按季节排序,而不是按剧集排序。假设每季不会超过 100 集,您可以按如下方式组合它们: 'episodeOrder' = xxyy 其中 'xx' 是 seasonnr,yy 是 Episodenr,例如,第 2 季第 3 集将变为:0203。

现在您可以按 EpisodeError 排序:
按剧集错误 asc 从节目顺序中选择 *;


吉尔特-扬

Are you just asking for a sql statement?
In that case, given your mention of 2 seperate variables, let's call them 'season' and episode respectively, you could do this:

ascending: select * from shows order by season asc, episode asc

descending: select * from shows order by season desc, episode desc

'most optimal', from a performance standpoint at least, would be to combine the 2 variables into a third (you can keep the 2 orginals for other stuff if you need to). Call that 'episodeOrder'.

'episodeOrder' has to sort first on season than on episode. ASsuming seasons will never have more than 100 episodes you could combine them as follows: 'episodeOrder' = xxyy where 'xx' is the seasonnr and yy is the episodenr, e.g season 2 episode 3 will become: 0203.

now you could sort by episodeError:
select * from shows order by episodeError asc;

hth
Geert-Jan

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文