Avatar billede vilhelm Nybegynder
22. september 2003 - 19:14 Der er 5 kommentarer og
1 løsning

Første og sidste - men kan man finde anden, tredie o.s.v.

Når man vælger totaler i en Access-forespørgsel kan man udvælge første og sidste, men hvordan udvælger man anden, tredie o.s.v.
Avatar billede terry Ekspert
22. september 2003 - 19:38 #1
well one way to do it would be to make a query seelction the TOP 2 (or 3) then make another query which selects the TOP 1 FROM that query but now soring the other way. and I am sure it could be done in one single SQL too :o)
Avatar billede terry Ekspert
22. september 2003 - 19:38 #2
soring = sorting
Avatar billede terry Ekspert
22. september 2003 - 19:52 #3
you could also use last to get the last from the Top 2
Avatar billede vilhelm Nybegynder
22. september 2003 - 23:21 #4
Sorry, but I am sure it can be done in SQL, but I don't know the statements...
Avatar billede mugs Novice
22. september 2003 - 23:39 #5
SELECT TOP 5 Tabel1.nr
FROM Tabel1
ORDER BY Tabel1.nr DESC;
Avatar billede terry Ekspert
23. september 2003 - 09:21 #6
Vilhelm>After taking a closer look at your question thn I think its best to say that it isnt easy although possible!
The first and last functions select the first or last values of the set of records. In other words if you GROUP by a number of fields then you have to make a query which finds the n'th value of ALL the records included in each SET. The first and last functions are buildt into the SQL language and I could imagine that when the SQL gets run then it looks at it and see's that you have a GROUPING then makes a sub SELECT taking either the TOP 1 sorted ascending or TOP 1 sorted descending and using each field in the grouping as the WHERE.
Because we dont have access to the SQL compiler we would have to do all of this manually, changing the code each time we change the fields we are grouping on. But I guess its possible (at a price :o) )
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Dyk ned i databasernes verden på et af vores praksisnære Access-kurser

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester