Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> podzapytanie + UNION
beel
post 9.05.2007, 22:09:16
Post #1





Grupa: Zarejestrowani
Postów: 87
Pomógł: 0
Dołączył: 20.04.2007

Ostrzeżenie: (0%)
-----


Witam!
Mam tabele:

STUDENT
student_id
name
sex


SCORE
student_id
event_id
score

EVENT
event_id
date
type

I teraz mam do wyświetlenia osobe która zdobyła najwiecej i osobe ktora zdobyla najmniej punktów, wiec:
  1. SELECT name, type, score, sex FROM student, score, event
  2. WHERE student.student_id=score.student_id AND event.event_id=score.event_id AND score=
  3.  
  4. (SELECT max(score) FROM score, event, student
  5. WHERE event.event_id=score.event_id)
  6.  
  7. UNION
  8.  
  9. SELECT name, type, score, sex FROM student, score, event
  10. WHERE student.student_id=score.student_id AND event.event_id=score.event_id AND score=
  11.  
  12. (SELECT min(score) FROM score, event, student
  13. WHERE event.event_id=score.event_id) ORDER BY score


I w efekcie jest wyświetlany poprawny wynik. (jakby ktos umial inaczej - prosciej to wykonac prosze zademonstrowac)
A teraz drugie zapytanie:
Który mężczyzna (oznaczenie 'M') uzsykał najwiecej z ktory najmniej punktów z testu (oznaczenie 'T'):

  1. SELECT name, type, score, sex FROM student, score, event
  2. WHERE student.student_id=score.student_id AND event.event_id=score.event_id AND sex='M' AND type='T' AND score=
  3.  
  4. (SELECT max(score) FROM score, event, student
  5. WHERE event.event_id=score.event_id)
  6.  
  7. UNION
  8.  
  9. SELECT name, type, score, sex FROM student, score, event
  10. WHERE student.student_id=score.student_id AND event.event_id=score.event_id AND sex='M' AND type='T' AND score=
  11.  
  12. (SELECT min(score) FROM score, event, student
  13. WHERE event.event_id=score.event_id) ORDER BY score

Prosze o wskazanie mi co jest źle w drugim zapytaniu bo mimo ze istenieja takie osoby nie wyświetla nic poza nazwami kolumn.

pzdr
Go to the top of the page
+Quote Post
envp
post 10.05.2007, 05:47:29
Post #2





Grupa: Zarejestrowani
Postów: 359
Pomógł: 1
Dołączył: 16.04.2006
Skąd: Łódź

Ostrzeżenie: (0%)
-----


Może problem tkwi w tym, że nie masz w którejś z innych tabel odpowiedniej relacji z drugą. Zamiast WHERE polecam LEFT JOIN smile.gif
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 19.07.2025 - 17:22