Jump to content
  • 0

[Gelöst] Spezielle SQL Abfrage - scheitere an Syntax und Fields


RingelZahn

Question

Hallo zusammen,

 

ich versuche mir eine SQL Abfrage zusammen zu basteln, die Artikelvarianten mit Preis und Lagerbestand auflistet.

 

Leider kriege ich nur die Artikel raus, aber nicht die einzelnen Varianten mit gepflegtem Bestand und Verkaufspreis.

 

Kann mir da jmd helfen? Bin für jeden Typ dankbar.

 

Bisher habe ich nur das:

SELECT b.`name` AS `Name`, a.`price` AS `Preis`, sav.`quantity` AS `Lagerbestand` FROM `pzsj_product`a 
LEFT JOIN `pzsj_product_lang` b ON (b.`id_product` = a.`id_product` AND b.`id_lang` = 2 AND b.`id_shop` = 1) 
LEFT JOIN `pzsj_stock_available` sav ON (sav.`id_product` = a.`id_product` AND sav.`id_product_attribute` = 0 AND sav.id_shop = 1 AND sav.id_shop_group = 0 ) JOIN `pzsj_product_shop` sa ON (a.`id_product` = sa.`id_product` AND sa.id_shop = a.id_shop_default) 
WHERE 1 ORDER BY sav.`quantity` ASC LIMIT 0, 50

und das gibt mir folgendes aus:

 

post-1286444-0-20726100-1470132718_thumb.jpg

Link to comment
Share on other sites

10 answers to this question

Recommended Posts

  • 0

maybe this one can help

SELECT
    p.id_product,
    pa.id_product_attribute as id_product_attribute,
    pa.reference,
    CONCAT(p.supplier_reference, " - ", pa.supplier_reference) as supplier_reference,
    pa.upc,
    pa.price,
    pl.name,
    GROUP_CONCAT(DISTINCT(pal.name) SEPARATOR ", ") as combination,
    pq.quantity
FROM ps_product p
LEFT JOIN ps_product_attribute pa ON (p.id_product = pa.id_product)
LEFT JOIN ps_stock_available pq ON (p.id_product = pq.id_product AND pa.id_product_attribute = pq.id_product_attribute)
LEFT JOIN ps_product_lang pl ON (p.id_product = pl.id_product)
LEFT JOIN ps_product_attribute_combination pac ON (pa.id_product_attribute = pac.id_product_attribute)
LEFT JOIN ps_attribute_lang pal ON (pac.id_attribute = pal.id_attribute)
LEFT JOIN ps_product_attribute_image pai on(pa.id_product_attribute = pai.id_product_attribute)
WHERE pl.id_lang = 1
AND pal.id_lang = 1
GROUP BY pa.reference

union

SELECT
    p.id_product,
    "" as id_product_attribute,
    p.reference,
    p.supplier_reference,
    p.upc,
    p.price,
    pl.name,
    "" as combination,
    p.quantity
FROM ps_product p
LEFT JOIN ps_stock_available pq ON (p.id_product = pq.id_product)
LEFT JOIN ps_product_lang pl ON (p.id_product = pl.id_product)
WHERE pl.id_lang = 1
GROUP BY p.reference

ORDER BY id_product, id_product_attribute 
Link to comment
Share on other sites

  • 0

Auf die Schnelle ... Würde bei mir ungefähr so aussehen (vorausgesetzt, du hast keine verschachtelten Attribute):

SELECT DISTINCT p.id_product, pl.name, al.name AS attribut, p.price, sa.quantity

FROM ps_product p 
LEFT JOIN ps_product_lang pl ON p.id_product=pl.id_product
RIGHT JOIN ps_stock_available sa ON p.id_product=sa.id_product
LEFT JOIN ps_product_attribute_combination ac ON (sa.id_product_attribute=ac.id_product_attribute AND sa.id_product_attribute!=0)
LEFT JOIN ps_attribute_lang al ON ac.id_attribute=al.id_attribute

WHERE p.active=1
AND pl.id_lang=1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...