-- 
-- 売上実績表（担当者別得意先別）
-- 
CREATE OR REPLACE VIEW v_sales_actual_result_table_by_rep_customer
AS 
SELECT
    sales_date_y,
    sales_date_m,
    sales_date_ym,
    customer_code,
    customer_name,
    rep_name_kana, -- 担当者カナ
    rep_name, -- 担当者名前
    SUM(
        pure_sales
    ) AS 'sum_pure_sales',  -- 純売上額
    SUM(
        gross_profit
    ) AS 'gross_profit_amount', -- 粗利額
    ROUND(
        (
            SUM(gross_profit)
            /
            SUM(pure_sales)
        )
    , 1) AS 'gross_profit_rate' -- 粗利率(粗利額/純売上額 四捨五入)


-- ｜売上実績表
FROM v_sales_actual_result_table

GROUP BY 
    rep_name_kana, -- 担当者カナ
    rep_name, -- 担当者名
    customer_code,
    customer_name,
    sales_date_y,
    sales_date_m,
    sales_date_ym