Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [MySQL] Select case when, grupowanie cen produktow w jednym zapytaniu
Forum PHP.pl > Forum > Przedszkole
Agape
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 ...
poli25
  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`
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.