我尝试执行的子请求被阻止,但我不知道该怎么做。我有 4 张桌子:
- 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
如果有人有想法。
开23