gpt4 book ai didi

mysql - 如何将 sum 的结果存储到可以在查询中使用的标识符中?

转载 作者:行者123 更新时间:2023-11-30 22:48:58 24 4
gpt4 key购买 nike

SELECT *,


SUM(

b1.bit_sum_excl * b1.bit_quantity -
if(b1.bit_deduction_percentage = 1, (b1.bit_deduction / 100)*(b1.bit_sum_excl * b1.bit_quantity), b1.bit_deduction)

) as _total_unconverted,

/*************** _total_unconverted * 0.15 as some_val; ****************/


FROM `bill_items` b1

LEFT JOIN clients_packing_list ON (b1.bit_cli_pack_list_id = clients_packing_list.cli_pack_list_id)


WHERE b1.bit_cli_bill_id = 1 OR b1.bit_cli_bill_id = 0

我希望能够添加一个表达式

_total_unconverted * 0.15 as _converted

进入选择。

目前它提示它不是一个列。

有没有办法做到这一点,还是我必须复制粘贴 SUM 代码并添加乘数?

最佳答案

SELECT *,SOURCEQUERY._total_unconverted * 0.15 as some_val FROM
(
SELECT
SUM(
b1.bit_sum_excl * b1.bit_quantity -
if(b1.bit_deduction_percentage = 1, (b1.bit_deduction / 100)*(b1.bit_sum_excl * b1.bit_quantity), b1.bit_deduction)
) as _total_unconverted
FROM bill_items AS b1
LEFT JOIN clients_packing_list ON (b1.bit_cli_pack_list_id = clients_packing_list.cli_pack_list_id)
WHERE b1.bit_cli_bill_id = 1 OR b1.bit_cli_bill_id = 0
) AS SOURCEQUERY

关于mysql - 如何将 sum 的结果存储到可以在查询中使用的标识符中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28702252/

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