【发布时间】:2017-02-11 03:19:54
【问题描述】:
我已经尝试了一个小时左右来解决这个问题,但无法弄清楚。有人可以指出我正确的方向吗?我正在使用 Oracle SQL Developer 的 OE 模式中的数据。
我需要显示在 list_price 中折扣最大的产品的产品类别名称。
这是我的代码:
SELECT ct.category_name, ROUND((pi.list_price pi.min_price)*100/pi.list_Price) AS Percent_Discount
FROM oe.product_information pi JOIN oe.categories_tab ct ON pi.category_id = ct.category_id
GROUP BY ct.category_name, ROUND((pi.list_price-pi.min_price)*100/pi.list_Price)
ORDER BY ROUND((pi.list_price-pi.min_price)*100/pi.list_Price) desc;
Here is an image of my results of the query
结果实际上一直下降到 150 左右,其中包括每一个产品。
我的问题是:我如何得到它,所以我的百分比数字是小数点后两位而不是四舍五入成整数?我知道我使用了 round 语句,但我这样做只是因为没有它,数字大约是 15 位。 另外,您认为我的代码是否正确回答了问题?我觉得我应该只显示折扣最大的前 10 或 20 个类别名称。无论如何我可以这样做而不是列出所有这些吗?
【问题讨论】: