Vinnaren i pepparkakshustävlingen!
2009-03-04, 18:44
  #1
Medlem
Håller på att göra en databas med "lagerstatus".

Såhär ser frågan ut, som ej funkar:

SELECT *, COUNT(byxorID) as Antalbyxor FROM ((Clothes INNER JOIN Categories Using(CategoryID)) WHERE CategoryID=1) LEFT JOIN Byxor USING(ClothesID) GROUP BY(ClothesID)

Tabllerna ser ut såhär:
Categories har namn+CategoryID.
Clothes har CategoryID, ClothesID, (+Clothesname osv.)
Byxor har ClothesID, byxorID (+Byxorname osv.).

Det jag vill kunna få fram är Antal byxor inom ett visst ClothesID, samtidigt som jag på sidan endast vill ha fram ClothesID'n från Categori 1 (CategoryID=1).


OBS denna funkar:
SELECT *, COUNT(antalbyxor) as Antalbyxor FROM ((Clothes INNER JOIN Categories Using(CategoryID)) LEFT JOIN Byxor USING(ClothesID) GROUP BY(ClothesID)

Men den visar ju alla ClothesID'n. Felet verkar sitta i WHERE CategoryID=1

Hoppas ni förstår vad jag menar och kan hjälpa mig!
__________________
Senast redigerad av NoLeafClover 2009-03-04 kl. 19:39.
Citera
2009-03-04, 21:18
  #2
Medlem
Ingen som kan?
Citera
2009-03-04, 22:24
  #3
Moderator
Protons avatar
Citat:
Ursprungligen postat av NoLeafClover
Håller på att göra en databas med "lagerstatus".

Såhär ser frågan ut, som ej funkar:

SELECT *, COUNT(byxorID) as Antalbyxor FROM ((Clothes INNER JOIN Categories Using(CategoryID)) WHERE CategoryID=1) LEFT JOIN Byxor USING(ClothesID) GROUP BY(ClothesID)

Tabllerna ser ut såhär:
Categories har namn+CategoryID.
Clothes har CategoryID, ClothesID, (+Clothesname osv.)
Byxor har ClothesID, byxorID (+Byxorname osv.).

Det jag vill kunna få fram är Antal byxor inom ett visst ClothesID, samtidigt som jag på sidan endast vill ha fram ClothesID'n från Categori 1 (CategoryID=1).


OBS denna funkar:
SELECT *, COUNT(antalbyxor) as Antalbyxor FROM ((Clothes INNER JOIN Categories Using(CategoryID)) LEFT JOIN Byxor USING(ClothesID) GROUP BY(ClothesID)

Men den visar ju alla ClothesID'n. Felet verkar sitta i WHERE CategoryID=1

Hoppas ni förstår vad jag menar och kan hjälpa mig!

Den här borde åstadkomma det du vill?

Kod:
SELECT *, COUNT(byxorID) as Antalbyxor FROM ((Clothes INNER JOIN Categories Using(CategoryID))) LEFT JOIN Byxor USING(ClothesID) WHERE Categories.CategoryID=1 GROUP BY(ClothesID)
Citera
2009-03-05, 00:24
  #4
Medlem
Citat:
Ursprungligen postat av Proton
Den här borde åstadkomma det du vill?

Kod:
SELECT *, COUNT(byxorID) as Antalbyxor FROM ((Clothes INNER JOIN Categories Using(CategoryID))) LEFT JOIN Byxor USING(ClothesID) WHERE Categories.CategoryID=1 GROUP BY(ClothesID)


Fungerade utmärkt! Tack!!
Citera

Stöd Flashback

Flashback finansieras genom donationer från våra medlemmar och besökare. Det är med hjälp av dig vi kan fortsätta erbjuda en fri samhällsdebatt. Tack för ditt stöd!

Stöd Flashback