我被一個子請求阻塞,我嘗試做,但我不知道該怎麼做。 我有4個表:子請求MySQL
- jos_vm_products =>所有產品存儲
- jos_vm_order_items =>在訂單中的項目
- jos_vm_order =>使
- stock_web_brut =>我的產品 的股票
我希望得到一個特定產品的所有信息:
- (完成)該產品的
- 的信息表中的jos_vm_products(完成)的庫存數
- 其在«未決»特定產品的(封端的)
這裏是我的第一個請求:
SELECT `product_id` , `product_weight` , `cdate` , `mdate` , `product_name` , `product_sales` , `product_sku` , `product_in_stock` , SUM(stock_bloque) AS 'stock_bloque', SUM(stock_total) AS 'stock_total', SUM(stock_vente) AS 'stock_vente', ref
FROM jos_vm_product t1
INNER JOIN `stock_web_brut` t2 ON t1.product_sku LIKE CONCAT(t2.ref, '%')
GROUP BY product_id;
而且我覺得我應該做這樣子請求:
SELECT
(
SELECT COUNT(t5.product_id)
FROM jos_vm_product t5
INNER JOIN jos_vm_order_item t6 ON t5.product_id = t6.product_id
WHERE order_status = 'P' AND t5.product_id = 12
) AS "nombre_produit_pending",
`product_id` ,
`product_weight` ,
`cdate` , `mdate` ,
`product_name` ,
`product_sales` ,
`product_sku` ,
`product_in_stock` ,
SUM(stock_bloque) AS 'stock_bloque',
SUM(stock_total) AS 'stock_total',
SUM(stock_vente) AS 'stock_vente',
ref
FROM jos_vm_product t1
INNER JOIN `stock_web_brut` t2 ON t1.product_sku LIKE CONCAT(t2.ref, '%')
GROUP BY product_id
,而不是«12»而且,我想我應該這樣做:
WHERE order_status = 'P' AND t5.product_id = t1.product_id
但我有一個循環
下面是表:http://kai23.fr/myam.svg(我不能發表圖片)
而對於結果,這將是類似的東西:
`product_id` | [...] | 'number_of_orders_in_pending_for_this_product' |
12 | [...] | 15
13 | [...] | 5
14 | [...] | 3
如果有人有一個id EA。
Kai23
你能提供你的表結構?你的預期結果是什麼? – SubRed
你好,這裏是一個鏈接全表: http://kai23.fr/myam。SVG 而對於結果,這將是類似的東西: 'product_id', [...] 'stock_total', 'stock_vente', 'number_of_orders_in_pending_for_this_product' – Kai23