Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Problem 3 tabelki ->wynik
kyke
post 4.09.2007, 15:50:13
Post #1





Grupa: Zarejestrowani
Postów: 1
Pomógł: 0
Dołączył: 4.09.2007

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


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

Ten post edytował kyke 4.09.2007, 15:51:15
Go to the top of the page
+Quote Post
grush
post 5.09.2007, 21:36:54
Post #2





Grupa: Zarejestrowani
Postów: 14
Pomógł: 0
Dołączył: 21.06.2007

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


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
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: 12.06.2025 - 12:26