Rick Ratchford wrote:
> For example, say I have 15 Dates already extracted by a previous
> query.
>
> I need to now get the 40 records that start at each of those 15 Dates.
>
> Assuming this is a SORTED dataset in ascending order by Date, I would
> need to extract 40 records that start with the record at 2009-03-03,
> then 40 records starting with the record at 2008-11-05, and so-forth.
>
> Can I do this in one SQL statement and have it produce one Recordset
> of this result? Or would I have to run 15 different queries?

You would be better off with 15 separate queries, like this:

select * from myTable
where Date >= :anchorDate
order by Date asc limit 40;

If you insist, you can get everything with a single query - but it will 
be slow as molasses in winter:

select * from dateList dl join myTable t
on (
    select count(*) from myTable t1
    where t1.Date between dl.Date and t.Date
) <= 40
order by dl.Date, t.Date;

where dateList is the table (perhaps temporary) containing your 15 
dates.

Igor Tandetnik 



_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to