On Fri, Jul 2, 2010 at 12:06 PM, Igor Tandetnik <itandet...@mvps.org> wrote: > P Kishor <punk.k...@gmail.com> wrote: >> I think what Peng wants is that given table of type_id >> >> 5 >> 5 >> 5 >> 5 >> 5 >> 4 >> 4 >> 4 >> 7 >> 7 >> 8 >> 8 >> 8 >> 8 >> >> if 'n' is 3, the desired result is >> >> 5 >> 5 >> 5 >> 4 >> 4 >> 4 >> 7 >> 7 >> 8 >> 8 >> 8 >> >> I don't know how to do that with sql. > > Well, if you insist: > > select type_id from foods f1 > where ( > select count(*) from foods f2 > where f2.type_id = f1.type_id > and f2.rowid < f1.rowid) < 3; >
I was going to add "That is an Igor-question" to "I don't know how to do that with sql." I have no idea how you do this, but if ever I meet you in person, I will be too awestruck to say anything beyond "SELECT.." > Igor Tandetnik > > _______________________________________________ > sqlite-users mailing list > sqlite-users@sqlite.org > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users > -- Puneet Kishor http://www.punkish.org Carbon Model http://carbonmodel.org Charter Member, Open Source Geospatial Foundation http://www.osgeo.org Science Commons Fellow, http://sciencecommons.org/about/whoweare/kishor Nelson Institute, UW-Madison http://www.nelson.wisc.edu ----------------------------------------------------------------------- Assertions are politics; backing up assertions with evidence is science ======================================================================= _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users