I forgot to also factor out the ORDER BY.  So, the updated query is:

---------------------
with t as (
 select GroupName, JobName, Start, End, Status,
        (strftime('%s', End) - strftime('%s', Start)) as Length
   from ReportJobs
   where PlanDate = '2014-02-13'
   order by Length desc
 )
select * from (select * from t where GroupName like 'GRP01%' LIMIT 10)
UNION ALL
select * from (select * from t where GroupName like 'GRP04%' LIMIT 10)
UNION ALL
select * from (select * from t where GroupName like 'GRP12%' LIMIT 10)
UNION ALL
select * from (select * from t where GroupName like 'GRP15%' LIMIT 10)
UNION ALL
select * from (select * from t where GroupName like 'GRP20%' LIMIT 10);
---------------------

The double select [select * from (select * from t ...] is required because LIMIT is only allowed at the end of a UNION, so you need a sub-query to overcome this. (BTW, this seems like an artificial restriction that could be removed, but I could be wrong.)
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to