SELECT 
    p.ID AS producto_id,
    p.post_title AS nombre_producto,
    sku.meta_value AS sku,
    agustina.meta_value AS stock_tienda_agustina,
    tienda.meta_value AS stock_tienda,
    (
        SELECT SUM(spt.stock)
        FROM stocks_por_tiendas spt
        WHERE spt.producto_id = p.ID
          AND spt.store = 3
          AND spt.area_id IN (3, 4)
    ) AS stock_store3_area3_4
FROM wp_posts p
LEFT JOIN wp_postmeta sku 
    ON sku.post_id = p.ID AND sku.meta_key = '_sku'
LEFT JOIN wp_postmeta agustina 
    ON agustina.post_id = p.ID AND agustina.meta_key = '_stock_tienda_agustina'
LEFT JOIN wp_postmeta tienda 
    ON tienda.post_id = p.ID AND tienda.meta_key = '_stock_tienda'
LEFT JOIN wp_postmeta tipo
    ON tipo.post_id = p.ID AND tipo.meta_key = '_producto_tipo'
WHERE p.post_type = 'product'
  AND tipo.meta_value = '1'
ORDER BY CAST(agustina.meta_value AS UNSIGNED) ASC;
