Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> skomplikowane zapytanie
Anna
post 14.03.2007, 14:25:00
Post #1





Grupa: Zarejestrowani
Postów: 11
Pomógł: 0
Dołączył: 21.11.2006

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


Zapytanie powinno zwracać:
- dane wszystkich userów users_data.*
- sumę punktów zdobytych przez usera w danym teście SUM(users_asks.point)+SUM(answers.point), lub NULL jeśli user testu nie wypełniał
- maksymalną sumę punktów jaką user mógł zdobyć w danym teście

Macie jakieś pomysły? winksmiley.jpg

Kombinuję w ten sposób:

  1. SELECT users_data. * , ask.suma + ans.suma, ask.max + ans.max
  2. FROM users_data LEFT JOIN (
  3. SELECT SUM( users_asks.point ) AS suma, COUNT( asks.ask_id ) AS max, users_asks.user_id
  4. FROM users_asks, asks
  5. WHERE users_asks.ask_id = asks.ask_id
  6. GROUP BY users_asks.user_id, asks.test_id
  7. ) AS ask
  8. USING ( user_id )
  9. LEFT JOIN (
  10.  
  11. SELECT SUM( answers.point ) AS suma, COUNT( asks.ask_id ) AS max, users_answers.user_id
  12. FROM users_answers, answers, asks
  13. WHERE users_answers.answer_id = answers.answer_id AND answers.ask_id = asks.ask_id
  14. GROUP BY users_answers.user_id, asks.test_id
  15. ) AS ans
  16. USING ( user_id )


questionmark.gifquestionmark.gif

Ten post edytował Anna 16.03.2007, 17:38:56
Go to the top of the page
+Quote Post

Posty w temacie


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: 18.07.2025 - 04:28