MySQL Forums
Forum List  »  German

Verschachtelte Abfrage über 3 Tabellen
Posted by: Sven Laske
Date: October 02, 2018 02:26AM

Hallo,

ich habe ein Problem bei einer verschachtelten Abfrage.
Es gibt 3 Tabellen
orders_products
gutschriften_products
products

Ich möchte abfragen, welche Artikel wie oft verkauft / retourniert werden.
Leider gibt mein Ansatz nur die Artikel aus, die verkauft UND auch mal retourniert wurden.
Artikel, die NIE verkauft oder NIE retourniert wurden werden nicht angezeigt.
Wo liegt der Fehler?

"SELECT products_quantity, P.products_date_added, A.products_id, A.products_name, products_ek AS EK
FROM ( select products_id, products_name, sum(products_quantity) as verkauft from orders_products group by products_id ) AS A
JOIN ( select final_price, products_id, products_name, sum(products_quantity) as gutschrift from gutschriften_products where final_price > 0 group by products_id) AS B
ON A.products_id=B.products_id
JOIN (select products_id,products_status,manufacturers_id,products_quantity,products_ek,products_price from products) AS P ON P.products_id = B.products_id order by ".$db_orderby." ".$sorted.", products_id"

Mit Joins habe ich leider nicht so viel Erfahrung.

Danke schonmal für die Hilfe

Options: ReplyQuote


Subject
Views
Written By
Posted
Verschachtelte Abfrage über 3 Tabellen
505
October 02, 2018 02:26AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.