在Oracle中,我想编写一个SELECT查询,它会在现有列中找到1.75%的折扣,每列中包含整数并将其四舍五入到最接近的美元。
我的查询有点失误,但无法弄清楚如何编写公式来执行百分比计算。
SELECT R.LAST_NAME, O.RENT_FEE, ROUND(RENT_FEE,0) AS DISCOUNT
FROM ROOM_UNIT R, OWNER O
WHERE R.OWNER_NUM = O.OWNER_NUM
答案 0 :(得分:2)
从数学课程中我们知道按x
%折扣相当于乘以
(1-x/100)
在您的情况下,折扣1.75%意味着乘以(1 - 0.0175)
或0.9825
:
SELECT R.LAST_NAME, O.RENT_FEE, ROUND((1 - 0.0175) * RENT_FEE,0) AS DISCOUNT
FROM ROOM_UNIT R, OWNER O -- ^^^^^^^^^^^^
WHERE R.OWNER_NUM = O.OWNER_NUM