Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [MySQL] Select case when, grupowanie cen produktow w jednym zapytaniu
Agape
post 11.04.2016, 13:11:20
Post #1





Grupa: Zarejestrowani
Postów: 384
Pomógł: 13
Dołączył: 16.06.2006

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


Mam tabele z produktami gdzie jedna z kolumn jest `cena`, teraz musze pogrupowac produkty jednym zapytaniem zeby wiedziec ile jest w kazdym z podanych zakresow cenowych. Tworze wiec pytanie z case when:
  1. select count(`id`) as `ilosc`, case
  2. when `cena` < 1000 then '0 - 1000'
  3. when `cena` >= 2000 and `cena` < 3000 then "2000 - 3000"
  4. when `cena` >= 3000 and `cena` < 4000 then "3000 - 4000"
  5. as `range`
  6. from `produkty`


no i mam blad:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'as `range` from `produkty`'. Nie moge dojsc czemu tam jest blad ...


--------------------
Go to the top of the page
+Quote Post
poli25
post 11.04.2016, 13:15:47
Post #2





Grupa: Zarejestrowani
Postów: 239
Pomógł: 20
Dołączył: 19.02.2010

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


  1. select count(`id`) as `ilosc`, case
  2. when `cena` < 1000 then '0 - 1000'
  3. when `cena` >= 2000 and `cena` < 3000 then "2000 - 3000"
  4. when `cena` >= 3000 and `cena` < 4000 then "3000 - 4000"
  5. as `range`
  6. from `produkty`

zamień na
  1. select count(`id`) as `ilosc`, case
  2. when `cena` < 1000 then '0 - 1000'
  3. when `cena` >= 2000 and `cena` < 3000 then "2000 - 3000"
  4. when `cena` >= 3000 and `cena` < 4000 then "3000 - 4000"
  5. else "Nothing" End as `range`
  6. from `produkty`


Ten post edytował poli25 11.04.2016, 13:16:05
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.05.2025 - 09:21