グループごとに最大の nタグを使用して多くの質問を読みましたがUNION ALL
、この SQL クエリのトリックよりも優れた解決策を見つけることができません。
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);
5 つの異なるグループ ( GRP01%、GRP04%、GRP12%、GRP15%、およびGRP20% )から最長の 10 個のジョブを選択したいと考えています。
私はSQLiteを使用しています。および列
の要素は、 ISO 8601 形式です。各ジョブの長さを計算してから、
グループごとに計算します。Start
End
(strftime('%s', End) - strftime('%s', Start)) as Length
ORDER BY Length DESC LIMIT 10
このクエリを (SQLite を使用して) 実行する最も簡単で優れた方法を知っていますか?