列
amount: 500
discount_percentage: 50
如何选择以250的金额结束?
由于
Ĵ
答案 0 :(得分:17)
试试这个:
SELECT amount - (amount * discount_percentage / 100)
FROM tableA;
答案 1 :(得分:3)
尝试使用:
SELECT (amount * ((100 - discount_percentage) / 100)) as result FROM tableA
答案 2 :(得分:1)
尝试这种简单的方法。
SELECT amount * .50
FROM TableA;
答案 3 :(得分:0)
创建一个功能
DROP FUNCTION IF EXISTS REMOVE_PERCENT;
DELIMITER //
CREATE FUNCTION REMOVE_PERCENT(amount decimal(10,2),perc INT(10))
RETURNS decimal(10,2)
RETURN amount - (amount*perc/100);
现在你可以使用它了
SELECT REMOVE_PERCENT(amount,discount_percentage) FROM tableA;
SELECT REMOVE_PERCENT(amount,discount_percentage) FROM tableB;
UPDATE tableA SET `result` = REMOVE_PERCENT(amount,discount_percentage) WHERE `discount_percentage` >0