SQLite - 按长度排序的5个不同组中的前10名

时间:2014-09-03 08:37:38

标签: sql sqlite limit-per-group

我使用最大-n-group-group 标记阅读了很多问题,但我找不到比此{1}}技巧更好的解决方案:< / p>

UNION ALL

我想为五个不同的小组选择十个最长的工作( GRP01% GRP04% GRP12% GRP15 % GRP20%)。

我使用的是SQLite select * from (select GroupName, JobName, Start, End, Status, (strftime('%s', End) - strftime('%s', Start)) as Length from ReportJobs where PlanDate = '2014-02-13' and GroupName like 'GRP01%' ORDER BY Length DESC LIMIT 10) UNION ALL select * from (select GroupName, JobName, Start, End, Status, (strftime('%s', End) - strftime('%s', Start)) as Length from ReportJobs where PlanDate = '2014-02-13' and GroupName like 'GRP04%' ORDER BY Length DESC LIMIT 10) UNION ALL select * from (select GroupName, JobName, Start, End, Status, (strftime('%s', End) - strftime('%s', Start)) as Length from ReportJobs where PlanDate = '2014-02-13' and GroupName like 'GRP12%' ORDER BY Length DESC LIMIT 10) UNION ALL select * from (select GroupName, JobName, Start, End, Status, (strftime('%s', End) - strftime('%s', Start)) as Length from ReportJobs where PlanDate = '2014-02-13' and GroupName like 'GRP15%' ORDER BY Length DESC LIMIT 10) UNION ALL select * from (select GroupName, JobName, Start, End, Status, (strftime('%s', End) - strftime('%s', Start)) as Length from ReportJobs where PlanDate = '2014-02-13' and GroupName like 'GRP20%' ORDER BY Length DESC LIMIT 10); Start列中的元素是ISO 8601格式 我使用End来计算每个作业的长度,然后使用(strftime('%s', End) - strftime('%s', Start)) as Length来计算每个作业。

您是否知道执行此查询的最简单/更好的方法(使用SQLite)?

0 个答案:

没有答案