gpt4 book ai didi

mysql - 合并 2 个 SELECT LEFT JOIN 查询,联合/声明 AS 不起作用

转载 作者:行者123 更新时间:2023-11-29 07:33:37 25 4
gpt4 key购买 nike

我有这个 select 语句,它运行一个标题为“product_id”和一个值的列。

SELECT meta_value as product_id
FROM ctc_woocommerce_order_itemmeta
LEFT JOIN ctc_woocommerce_order_items ON ctc_woocommerce_order_itemmeta.order_item_id = ctc_woocommerce_order_items.order_item_id
WHERE meta_key = '_product_id'
AND order_id = 3988

我希望将结果与此语句结合起来:

SELECT meta_value as variation_id
FROM ctc_woocommerce_order_itemmeta
LEFT JOIN ctc_woocommerce_order_items ON ctc_woocommerce_order_itemmeta.order_item_id = ctc_woocommerce_order_items.order_item_id
WHERE meta_key = '_variation_id'
AND order_id = 3988

如何结合两者?我试过 UNION,也试过与下面类似的语句,但 phpMyAdmin 崩溃了。

SELECT x.a, y.b FROM (SELECT * from a) as x, (SELECT * FROM b) as y

我正在寻找包含 2 列的输出:

1 x product_id

1 x variation_id

最佳答案

我想你把 SELECT 写错了地方。

SELECT (
SELECT meta_value as product_id
FROM ctc_woocommerce_order_itemmeta
LEFT JOIN ctc_woocommerce_order_items ON ctc_woocommerce_order_itemmeta.order_item_id = ctc_woocommerce_order_items.order_item_id
WHERE meta_key = '_product_id'
AND order_id = 3988
) as product_id,
(
SELECT meta_value as variation_id
FROM ctc_woocommerce_order_itemmeta
LEFT JOIN ctc_woocommerce_order_items ON ctc_woocommerce_order_itemmeta.order_item_id = ctc_woocommerce_order_items.order_item_id
WHERE meta_key = '_variation_id'
AND order_id = 3988
) as variation_id;

关于mysql - 合并 2 个 SELECT LEFT JOIN 查询,联合/声明 AS 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49942411/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com