Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [MySQL]Zapytanie sql
meehow18
post 11.08.2016, 23:14:06
Post #1





Grupa: Zarejestrowani
Postów: 102
Pomógł: 0
Dołączył: 10.01.2010

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


Witam,
mam takie zapytanie:
  1. SELECT COUNT('subscriber_id') AS `count`, DATE_FORMAT( FROM_UNIXTIME( `date` ), '%d' ) AS 'day', DATE_FORMAT( FROM_UNIXTIME( `date` ), '%Y-%m-%d' ) AS 'date_formatted'
  2. FROM `subscribers`
  3. LEFT JOIN `autoresponder` ON `subscribers`.`id_autoresponder` = `autoresponder`.`id_autoresponder`
  4. LEFT JOIN `users` ON `autoresponder`.`user_id` = `users`.`user_id`
  5. WHERE `users`.`user_id` = 12
  6. AND `date` >= 1470348295
  7. AND `date` <= 1470953095
  8. AND `subscribers`.`active` = 1
  9. GROUP BY `date`
  10. ORDER BY `date_formatted` ASC


Wszystko było by ok, ale czasami zwraca mi:

  1. (
  2. [0] => Array
  3. (
  4. [count] => 1
  5. [day] => 09
  6. [date_formatted] => 2016-08-09
  7. )
  8.  
  9. [1] => Array
  10. (
  11. [count] => 1
  12. [day] => 09
  13. [date_formatted] => 2016-08-09
  14. )
  15.  
  16. [2] => Array
  17. (
  18. [count] => 1
  19. [day] => 11
  20. [date_formatted] => 2016-08-11
  21. )
  22.  
  23. )
  24.  


A chciałbym, aby zwróciło:

  1. (
  2. [0] => Array
  3. (
  4. [count] => 2
  5. [day] => 09
  6. [date_formatted] => 2016-08-09
  7. )
  8.  
  9.  
  10. [1] => Array
  11. (
  12. [count] => 1
  13. [day] => 11
  14. [date_formatted] => 2016-08-11
  15. )
  16.  
  17. )
  18.  
Go to the top of the page
+Quote Post
darko
post 11.08.2016, 23:46:31
Post #2





Grupa: Zarejestrowani
Postów: 2 885
Pomógł: 463
Dołączył: 3.10.2009
Skąd: Wrocław

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


Spróbuj z distinct:

SELECT DISTINCT COUNT('subscriber_id') AS `count`, ...


--------------------
Nie pomagam na pw, tylko forum.
Go to the top of the page
+Quote Post
meehow18
post 12.08.2016, 04:32:29
Post #3





Grupa: Zarejestrowani
Postów: 102
Pomógł: 0
Dołączył: 10.01.2010

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


Właśnie też próbowałem i też lipa, bo nie zlicza tego drugiego.

  1. (
  2. [0] => Array
  3. (
  4. [count] => 1
  5. [day] => 09
  6. [date_formatted] => 2016-08-09
  7. )
  8.  
  9. [1] => Array
  10. (
  11. [count] => 1
  12. [day] => 11
  13. [date_formatted] => 2016-08-11
  14. )
  15.  
  16. )
Go to the top of the page
+Quote Post
mmmmmmm
post 12.08.2016, 06:22:35
Post #4





Grupa: Zarejestrowani
Postów: 1 421
Pomógł: 310
Dołączył: 18.04.2012

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


GROUP BY DATE_FORMAT( FROM_UNIXTIME( `date` ), '%Y-%m-%d' )
zamiast
GROUP BY `date`
Go to the top of the page
+Quote Post
meehow18
post 12.08.2016, 09:45:06
Post #5





Grupa: Zarejestrowani
Postów: 102
Pomógł: 0
Dołączył: 10.01.2010

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


ok dzięki smile.gif
dałem GROUP BY 'date_formatted' bo to ta sama wartość wink.gif i działa ladnie 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: 16.07.2025 - 12:08