在这方面我已经做了很多环顾四周,并想在我们采取不同的策略之前用尽所有可能性。
以下查询:
SELECT
node.nid AS nid
FROM
node node
WHERE
(node.type in ('new_catalog_master'))
AND (SELECT
status
FROM
(SELECT
@COST := (SELECT
pm.field_price_matrix_ppu_value
FROM
node n
INNER JOIN content_type_new_catalog_master ncm ON ncm.nid = n.nid
INNER JOIN content_type_vendor_price_object vpo ON vpo.field_vpo_product_ref_nid = ncm.nid
INNER JOIN content_type_price_matrix pm ON pm.nid = vpo.nid
WHERE
ncm.nid = node.nid AND vpo.field_vpo_pref_vendor_value = 'yes' AND pm.field_price_matrix_quantity_value = (SELECT
MAX(ctpm.field_price_matrix_quantity_value)
FROM
content_type_price_matrix ctpm
WHERE
ctpm.nid = vpo.nid)),
@DATA_MARGIN := (SELECT
cs.low
FROM
competitor_stats cs
WHERE
cs.nid = node.nid),
@SUGGESTED_MARGIN := (1-(@COST/@DATA_MARGIN))*100,
@MARGIN := (SELECT
ctfmm.field_margin_matrix_gross_margin_value, ctfmm.field_margin_matrix_role_value
FROM
content_type_flexi_margin_matrix ctfmm
WHERE
ctfmm.nid = node.nid AND ctfmm.field_margin_matrix_role_value = 1),
@MARGIN_MAX := 5/100,
(ABS(@SUGGESTED_MARGIN-@MARGIN) > @SUGGESTED_MARGIN*@MARGIN_MAX) AS status
) as result);
回报:
Unknown column 'node.nid' in 'where clause'
如果我们将 nid 值硬编码到子查询中,则查询会返回一个值。是否可以在子查询中访问 node.nid?
由于某些限制,我们有点需要将子查询保留在 WHERE 子句中。