Avatar billede fredand Forsker
26. marts 2003 - 12:06 Der er 3 kommentarer og
2 løsninger

Tricky with PLSQL

Hello!

I got a database that looks like this in Oracle:
http://www.it-gymnasiet.info/programmering_c/databasebattle.jpg

And now I have a task to check like this:
Check with a SELECT that there is no doublestoring in the table BATTLE. No Armies can fight each other more than once, independent on LOCATION and COMBATTIME (the date for the combat).

This has to be solved with PLSQL.

So if any one can help me with this please let me know!

Best regards
Fredrik
Avatar billede teepee Nybegynder
26. marts 2003 - 12:44 #1
Kan du ikke lave en select count(battle_number), army1, army2 ... group by army1, army2 having count(battle_number) > 1 så ved du ihvertfald om der findes nogle
Avatar billede sluppermanden Nybegynder
26. marts 2003 - 13:49 #2
It would be easy to solvet in SQL, by making a double primary key
ad this to the create sentence;

Constraint pk_battle_army Primary Key(ARMY_1_NUMBER,ARMY_2_NUMBER);

that way it is not possible to have the 2 armys fighting each other twice.
Avatar billede tintin12 Nybegynder
26. marts 2003 - 19:27 #3
i don't think that the primary key answer is correct because armyX and armyY can be in any combination in the columns army_1_number and army_2_number
Avatar billede sluppermanden Nybegynder
26. marts 2003 - 22:48 #4
well, that was the general idea
Avatar billede fredand Forsker
28. marts 2003 - 12:46 #5
Thanks Guys!
Fredrik
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
Computerworld tilbyder specialiserede kurser i database-management

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