Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Problem 3 tabelki ->wynik
Forum PHP.pl > Forum > Bazy danych > MySQL
kyke
Proszę o pomoc :
Mam 3 tabelki:
Tabela: User ( User_id, User_name, User_adress, ....)
Tabela: Orders ( User_id, Order_id, ...... )
Tabela: Orders_item ( Order_id, Order_item_name, Product_quantity, ….)
 
SELECT
order_item.order_item_name, sum(order_item.Product_quantity), user.User_name, user.User_adress
FROM
order_item LEFT JOIN orders ON order_item.order_id=orders.order_id
LEFT JOIN user ON orders.user_id=user.user_id
WHERE order_item.order_item_sku <30
GROUP BY order_item.order_item_name;

Proszę pomóżcie bo chcę otrzymać wynik, jestem kiepski w sql-u:



------------------------- Oreder_item_name---------Order_item_name2--------Order_item_name..-------|
User_name1, User_adress-Sum of Product_quantity---Sum of Product_quantity--Sum of Product_quantity
User_name1, User_adress-Sum of Product_quantity---Sum of Product_quantity--Sum of Product_quantity
grush
witam, jest to tylko sugestia, nie wiem co chcesz uzyskać, czy zadziała i w czym jest błąd, proponuję taki styl:
(gdzies tam jeszcze SUM() dopisać trzeeba)

  1. SELECT
  2. users.User_id, users.User_name, users.User_adress,
  3. orders.User_id, orders.Order_id,
  4. item.Order_id, item.Order_item_name, item.Product_quantity, item.Order_item_sku
  5. FROM User AS users, Orders AS orders, Orders_item AS item
  6. WHERE users.User_id = orders.User_id AND orders.Order_id = item.Order_id AND item.Order_item_sku < 30
  7. GROUP BY users.User_id


pogrupowane wg Users_id, bo jeśli miało by być wg Order_item_name, to całe zapytanie trzeba przerobić i nie wiązać po User_id, bo to chyba niema sensu sad.gif
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.