Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> podzapytanie + UNION
beel
post
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

Posty w temacie
- beel   podzapytanie + UNION   9.05.2007, 22:09:16
- - envp   Może problem tkwi w tym, że nie masz w którejś z i...   10.05.2007, 05:47:29


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

 



RSS Aktualny czas: 22.08.2025 - 18:09