SKU in SQL statement
-
I have a custom plugin from a developer that is not available anymore and he wrote the following SQL query and now I should add the _sku to it. But I struggle to get it with all the left joins … So right now I get a result-list with product_id, post_title, date and quantity and now the resultlist should include the sku
The SQL:
SELECT PD.ID as product_id, PD.post_title, ddo.date, SUM(ddo.quantity) as quantity FROM dckk0_daily_orders ddo INNER JOIN ( SELECT p.ID, p.post_title FROM dckk0_posts p LEFT JOIN dckk0_postmeta pm1 ON pm1.post_id = p.ID WHERE p.post_type in('product', 'product_variation') AND p.post_status = 'publish' GROUP BY p.ID,p.post_title ) AS PD ON PD.ID = ddo.product_id INNER JOIN dckk0_posts p ON p.ID = ddo.order_id WHERE p.post_status in ('wc-pending', 'wc-processing', 'wc-on-hold', 'wc-completed') AND ddo.date >= DATE_FORMAT(CURDATE(),'%Y-%m-%d') GROUP BY PD.post_title, ddo.date ORDER BY ddo.date
Thanks and any help would be awesome werner
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘SKU in SQL statement’ is closed to new replies.