Avatar billede jokkejensen Novice
02. juni 2009 - 20:03 Der er 17 kommentarer og
1 løsning

Distinct - og flere værdier

Hey.

Jeg mener i mysql kan skrive distinct med en order by i min select clause, ala:

Select distinct(charName)as [Name], charLevel from Data order by charDate

Men når jeg forsøger med:

Select distinct charName as [Name], level from Data order by charDate

i access får jeg fejl.

Jeg ønsker i bund og grund, at trække charName distinct ud sorteret efter charDate, og tage resten af data fra rækken i et sql træk.

Lige nu, iterere jeg med kode alle navnene igennem, og det "sænker" den sku en del, der er over 4000 navne... og access.

Håber på hurtig hjælp, det sænker min debug lidt :)

På forhånd tak

/J
Avatar billede terry Ekspert
02. juni 2009 - 20:27 #1
You cant have an order by on a field which isnt selected

order by charDate
Avatar billede terry Ekspert
02. juni 2009 - 20:29 #2
try

Select distinct charName as [Name], level, charDate from Data order by charDate
Avatar billede jokkejensen Novice
02. juni 2009 - 20:35 #3
Tak, smid et svar :D
Avatar billede terry Ekspert
02. juni 2009 - 20:35 #4
selv tak
Avatar billede jokkejensen Novice
02. juni 2009 - 21:08 #5
naaa, den returnere stadig alle rækker, skal jeg oprette en ny ?

Vh ?
Avatar billede jokkejensen Novice
02. juni 2009 - 21:09 #6
jeg brugte:


Select distinct charName, charDate from Data order by charDate
Avatar billede jokkejensen Novice
02. juni 2009 - 21:11 #7
naaa fuck det, det er egentligt ligegodt.

Vh
Avatar billede terry Ekspert
03. juni 2009 - 12:04 #8
sorry, didnt see your comments, for some reason I'm not receiving mails from eksperten!


Are you still having problems? If so can you give an example of your data and what you expect in the result?
Avatar billede jokkejensen Novice
03. juni 2009 - 12:10 #9
iam at work atm but my table looks like:

[id]  [charName] [charLevel]  [charDate]
1        Jacob            3                      01-01-1900
2        Jacob            4                      01-02-1900
3        Ole                3                    01-02-1900

I need a resultset as:

[id]  [charName] [charLevel]  [charDate]
2      Jacob            4                      01-02-1900
3        Ole              3                    01-02-1900

So all the colums ordered by date, distinct name.

Thx
Jacob.
Avatar billede terry Ekspert
03. juni 2009 - 12:27 #10
Ok, I'll take a look later (after work) and put something togther for you.
Avatar billede jokkejensen Novice
03. juni 2009 - 12:31 #11
thx, i can supply u with access db if necessary.

/J
Avatar billede terry Ekspert
03. juni 2009 - 12:46 #12
Ok, send to ekspertenATsanthell.dk
AT = @
Avatar billede terry Ekspert
03. juni 2009 - 18:38 #13
have you sent me your dB?
Avatar billede jokkejensen Novice
03. juni 2009 - 20:04 #14
on its way m8
Avatar billede jokkejensen Novice
03. juni 2009 - 20:13 #15
Hej Terry.

I have attached the access database as 2007 and 2003.

The data is from a highscore list, i need alle the names distinct and all the other colums as a single row ordered by newest charDate.

My application needs to give me an fast overview about changes on the highscore, so do u know if its possible to make one sql call, and get 2 rows, giving one charName and 2 dates ?

I juse:

SELECT Data.charName, Data.charLevel, Data.charDate
FROM Data
WHERE  (Data.charDate=#1/6/2009 0:0:1# or Data.charDate=#1/6/2009 0:1:0#) and charName = 'Renegade'

But can i in the same SQL statement, take the difference of charBlood from the two dates ?

i have attached a screendumb of my applikation, right now i just take alle the names from the newest date and loop through em all;

string lastSql = "Select * from Data where charName = '"+Name+"' and (((data.charDate)=#"+dtLast.ToString("M/d/yyyy H:m:s")+"#))";
string nowSql = "Select * from Data where charName = '" + Name +"' and (((data.charDate)=#"+dtNow.ToString("M/d/yyyy H:m:s")+"#))";

But the call is very expensive as the database grows, therefore it could be neat if i could get the diffrence in charBlood in the same SQL

Thx in advance.

/Jacob.
Avatar billede jokkejensen Novice
03. juni 2009 - 20:14 #16
"The data is from a highscore list, i need alle the names distinct and all the other colums as a single row ordered by newest charDate."

is the original question giving 200 points, just tell me if i need to make a question more for the other part.

Thx
Jacob.
Avatar billede jokkejensen Novice
03. juni 2009 - 20:16 #17
the questions is, can i with the parameters "charName" and 2x "charDate" get the difference in charBlood in one sql call.
Avatar billede terry Ekspert
01. juli 2009 - 08:43 #18
Hi Jacob
What is the status on this question, did we ever find a solution?
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