Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Problem z zapytaniem SELECT
PKua
post
Post #1





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

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


Cześć. Gdy wykonuję zapytanie:
  1. SELECT `users`.`uid` AS `uid` , `login` , `reg_timestamp` , `rank` , `server_respect` , `forum_respect` , `last_visit_timestamp` , `accsongs` , `rejsongs` , `waitsongs`
  2. FROM `users`
  3. LEFT JOIN (
  4.  
  5. SELECT IFNULL (COUNT( * ), 0) AS `waitsongs` , `uid`
  6. FROM `songs`
  7. WHERE `status` =0
  8. GROUP BY `uid`
  9. ) AS `waitsongs` ON `waitsongs`.`uid` = `users`.`uid`
  10. LEFT JOIN (
  11.  
  12. SELECT IFNULL (COUNT( * ), 0) AS `accsongs` , `uid`
  13. FROM `songs`
  14. WHERE `status` =1
  15. GROUP BY `uid`
  16. ) AS `accsongs` ON `accsongs`.`uid` = `users`.`uid`
  17. LEFT JOIN (
  18.  
  19. SELECT IFNULL (COUNT( * ), 0) AS `rejsongs` , `uid`
  20. FROM `songs`
  21. WHERE `status` =2
  22. GROUP BY `uid`
  23. ) AS `rejsongs` ON `rejsongs`.`uid` = `users`.`uid`
  24. WHERE (
  25. `waitsongs` + `accsongs` + `rejsongs`
  26. ) > 0
  27. ORDER BY `reg_timestamp` DESC
  28. LIMIT 0 , 30


to nie zwraca nic, natomiast jak wykonuję:
  1. SELECT `users`.`uid` AS `uid` , `login` , `reg_timestamp` , `rank` , `server_respect` , `forum_respect` , `last_visit_timestamp` , `accsongs` , `rejsongs` , `waitsongs`
  2. FROM `users`
  3. LEFT JOIN (
  4.  
  5. SELECT IFNULL (COUNT( * ), 0) AS `waitsongs` , `uid`
  6. FROM `songs`
  7. WHERE `status` =0
  8. GROUP BY `uid`
  9. ) AS `waitsongs` ON `waitsongs`.`uid` = `users`.`uid`
  10. LEFT JOIN (
  11.  
  12. SELECT IFNULL (COUNT( * ), 0) AS `accsongs` , `uid`
  13. FROM `songs`
  14. WHERE `status` =1
  15. GROUP BY `uid`
  16. ) AS `accsongs` ON `accsongs`.`uid` = `users`.`uid`
  17. LEFT JOIN (
  18.  
  19. SELECT IFNULL (COUNT( * ), 0) AS `rejsongs` , `uid`
  20. FROM `songs`
  21. WHERE `status` =2
  22. GROUP BY `uid`
  23. ) AS `rejsongs` ON `rejsongs`.`uid` = `users`.`uid`
  24. WHERE
  25. `waitsongs` > 0
  26. ORDER BY `reg_timestamp` DESC
  27. LIMIT 0 , 30


to zwraca to co trzeba. Dlaczego tak się dzieje? W klauzuli WHERE nie można stosować rzeczy typu coś + coś + coś > czegoś?
Go to the top of the page
+Quote Post

Posty w temacie


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: 23.08.2025 - 11:49