gpt4 book ai didi

mysql - 按列中的特定值排序

转载 作者:行者123 更新时间:2023-11-29 19:28:59 24 4
gpt4 key购买 nike

我有账单表。现在,我想检索所有数据,但有折扣,所以折扣有两种类型,固定金额和百分比,百分比是小数形式,例如:-0.10 代表 10%,折扣必须是最后获取的它是按 asc 排序的。对不起,我的英语不好。这是我的表格:

id       |    bill_item_id       |      bill_item_amount
1 | 1 | 1000
2 | 3 | -0.12
3 | 2 | -100
4 | 4 | -0.15

bill_item_id = 2表示折扣是固定的,如果是百分比则bill_item_id可以是任意数字。

预期输出必须是:

id       |      bill_item_amount
1 | 1000
3 | -100
4 | -0.15
2 | -0.12

到目前为止我的查询:

SELECT * FROM billing_details order by bill_item_amount < 0 and bill_item_amount > -1 asc

我的查询仅检查百分比折扣,但我也想检查固定折扣。订单将是普通商品、固定折扣、百分比折扣升序。

最佳答案

试试这个

select
id, bill_item_amount
from
billing_details
order by
bill_item_amount desc;

关于mysql - 按列中的特定值排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41930684/

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