如何分配百分比金额项目

时间:2019-01-08 08:20:38

标签: sql-server

我有一个存储Order的表结构。假设我有一个订单,其中客户对每个商品要求3个Items和不同的Qty,每个Unit Price不同。 店主在所有25000上给他items的折扣,但后来客户来了,要求从订单中删除一个item,所以我想得到amount的{​​{1}} discount适用于该item,因此amountdiscount的{​​{1}}也适用于该订单。

item

1 个答案:

答案 0 :(得分:4)

如果我正确理解了您的情况,则需要计算一种货币单位的折扣(25 000/450 000),然后进行所有计算:

jQuery('.feature__content__target:last-child()').hide();

jQuery('.feature__content__tabs__selector').on('click', function(e) {
    var selector = jQuery(this).data('selector');
    var targets = jQuery('feature__content__target');
    var container = jQuery(this).closest('.feature__content');
    var target = container.find('div[data-target="' + selector + '"]');

    console.log(selector);

    targets.removeClass('show');
    target.addClass('show');    
});

输出:

;
WITH cte AS (
    SELECT 
        SALE_MASTER.ORDER_NUMBER,
        SUM(SALE_DETAIL.QUANTITY * SALE_DETAIL.PRICE) AS TOTAL_AMOUNT,
        SALE_MASTER.DISCOUNT_AMOUNT
    FROM SALE_DETAIL, SALE_MASTER
    WHERE SALE_DETAIL.ORDER_NUMBER = SALE_MASTER.ORDER_NUMBER
    GROUP BY SALE_MASTER.ORDER_NUMBER, SALE_MASTER.DISCOUNT_AMOUNT
)
SELECT 
    SALE_DETAIL.ITEM_NAME, 
    SALE_DETAIL.QUANTITY, 
    SALE_DETAIL.PRICE, 
    (SALE_DETAIL.QUANTITY * SALE_DETAIL.PRICE) * (cte.DISCOUNT_AMOUNT / cte.TOTAL_AMOUNT) AS ITEM_DISCOUNT_FOR_ALL_ITEMS,
    SALE_DETAIL.PRICE * (cte.DISCOUNT_AMOUNT / cte.TOTAL_AMOUNT) AS ITEM_DISCOUNT_FOR_ONE_ITEM
FROM SALE_DETAIL, cte
WHERE SALE_DETAIL.ORDER_NUMBER = cte.ORDER_NUMBER