jeudi 18 février 2016

Select first row in each group using group by in sqlite

I have a table in sqlite. I am trying to get the first row of each group. Although there were earlier questions regarding the same. I couldn't find solution in sqlite.

My table looks like this:

select * from geoview
MaxOfStatecountpercent | statepoolnumber | STATECODE
75                       4595              CA
75                       4595              FL
100                      6221              TX
100                      6221              MN
100                      4569              FL
100                      4569              CA
100                      5435              TX

I would like to query the first of MaxOfStatecountpercent and first of STATECODE from each statepoolnumber. The equivalent access sql query is :

select first(MaxOfStatecountpercent), statepoolnumber, first(STATECODE) from geoview group by statepoolnumber;

And the output expected is :

First(MaxOfStatecountpercent) | statepoolnumber | First(STATECODE)
75                              4595              CA
100                             6221              TX
100                             4569              FL
100                             5435              TX

I tried with "limit 1 " but did not work. How can i get a query equivalent in sqlite?

Aucun commentaire:

Enregistrer un commentaire