gpt4 book ai didi

mysql - 通过一个 mysql-query 获取值

转载 作者:行者123 更新时间:2023-11-29 23:55:08 24 4
gpt4 key购买 nike

通过以下查询,我获取不同类的值

$query = xtc_db_query("-- " . __LINE__ . __FILE__ . "
SELECT value
FROM " . TABLE_ORDERS_TOTAL . "
WHERE orders_id = " . $last_order . "
AND class = 'ot_shipping'
");
$orders_total_shipping = xtc_db_fetch_array($query);
$query = xtc_db_query("-- " . __LINE__ . __FILE__ . "
SELECT value
FROM " . TABLE_ORDERS_TOTAL . "
WHERE orders_id = " . $last_order . "
AND class='ot_tax'
");
$orders_total_tax = xtc_db_fetch_array($query);
$query = xtc_db_query("-- " . __LINE__ . __FILE__ . "
SELECT value
FROM " . TABLE_ORDERS_TOTAL . "
WHERE orders_id = " . $last_order . "
AND class='ot_total'
");
$orders_total = xtc_db_fetch_array($query);

是否可以通过一次查询获取值?

最佳答案

可能是这样的

$query = xtc_db_query("-- " . __LINE__ . __FILE__ . "
SELECT Case When class = 'ot_shipping' The value Else Null End As Shipping,
Case When class = 'ot_tax' The value Else Null End As Tax,
Case When class = 'ot_total' The value Else Null End As Total
FROM " . TABLE_ORDERS_TOTAL . "
WHERE orders_id = " . $last_order . "
");
$orders_total_shipping = xtc_db_fetch_array($query);

或者:

$query = xtc_db_query("-- " . __LINE__ . __FILE__ . "
SELECT value
FROM " . TABLE_ORDERS_TOTAL . "
WHERE orders_id = " . $last_order . "
AND class = 'ot_shipping'
Union All
SELECT value
FROM " . TABLE_ORDERS_TOTAL . "
WHERE orders_id = " . $last_order . "
AND class='ot_tax'
UNION ALL
SELECT value
FROM " . TABLE_ORDERS_TOTAL . "
WHERE orders_id = " . $last_order . "
AND class='ot_total'
");
$orders_total = xtc_db_fetch_array($query);

关于mysql - 通过一个 mysql-query 获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25421589/

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