gpt4 book ai didi

php - MySQL - 在需要时添加增值税

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

我有一系列包含或不包含增值税的产品。我总是想向客户显示包含增值税的价格,因此我有一个标志,说明价格是否包含增值税。目前我在 PHP 中添加了增值税,这意味着排序有些不对劲,因为 MySQL 是根据基本价格排序的,有时增值税会使结果乱序。

然后我想要的是在 MySQL 查询中在需要的地方自动将增值税添加到价格中。我怎样才能做到这一点?

我的产品表如下所示:

product_id, product_dayprice, product_weekprice, product_includevat

product_includevat 只是一个 bool 值,即 1 或 0...增值税存储为 PHP 变量

我的排序代码看起来是这样的,旨在将价格为 0 的产品放在最后

CASE product_daypriceWHEN 0 then 40000 ELSE product_dayprice END

最佳答案

如果 product_include_vat 是一个 bool 字段,那么它会很简单

SELECT product_weekprice + (product_weekprice * vat_rate * product_includevat)

如果 includevat 字段为 false,它将计算为整数 0,并且您的 vat 在乘法中被清零。

关于php - MySQL - 在需要时添加增值税,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12735157/

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