综合销售汇总, 数据排序调整

This commit is contained in:
king
2026-04-28 11:30:48 +08:00
parent 31c425af35
commit b14b28fbee

View File

@@ -1161,38 +1161,40 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectNewGrBiSaAggGroupHZList" resultType="java.util.Map">
SELECT
'自营品种' as bk,
IF(GROUPING (saler_name, zone_name) = 2, CONCAT(zone_name, "总计"), IFNULL(zone_name, '省区合计')) AS zone_name,
c.position,
saler_name,
-- GROUPING (saler_name, zone_name, c.position),
ROUND(SUM(IF(`use_month` = '1', this_month_sa_money, null)) / 10000, 2) AS month_sa_money_1,
ROUND(SUM(IF(`use_month` = '2', this_month_sa_money, null)) / 10000, 2) AS month_sa_money_2,
ROUND(SUM(IF(`use_month` = '3', this_month_sa_money, null)) / 10000, 2) AS month_sa_money_3,
ROUND(SUM(IF(`use_month` = '4', this_month_sa_money, null)) / 10000, 2) AS month_sa_money_4,
ROUND(SUM(IF(`use_month` = '5', this_month_sa_money, null)) / 10000, 2) AS month_sa_money_5,
ROUND(SUM(IF(`use_month` = '6', this_month_sa_money, null)) / 10000, 2) AS month_sa_money_6,
ROUND(SUM(IF(`use_month` = '7', this_month_sa_money, null)) / 10000, 2) AS month_sa_money_7,
ROUND(SUM(IF(`use_month` = '8', this_month_sa_money, null)) / 10000, 2) AS month_sa_money_8,
ROUND(SUM(IF(`use_month` = '9', this_month_sa_money, null)) / 10000, 2) AS month_sa_money_9,
ROUND(SUM(IF(`use_month` = '10', this_month_sa_money, null)) / 10000, 2) AS month_sa_money_10,
ROUND(SUM(IF(`use_month` = '11', this_month_sa_money, null)) / 10000, 2) AS month_sa_money_11,
ROUND(SUM(IF(`use_month` = '12', this_month_sa_money, null)) / 10000, 2) AS month_sa_money_12,
ROUND(SUM(this_month_sa_money) / 10000, 2) AS year_sa_money
FROM
new_gr_bi_sa_agg_month_count a
LEFT JOIN gr_report.gr_contacts c ON a.saler_name = c.`name`
AND a.zone_name = c.zone
WHERE
use_year = YEAR(CURDATE())
AND sale_type_name = '自营品种'
GROUP BY
zone_name,
saler_name,
c.position WITH ROLLUP
select t.* from (
SELECT
'自营品种' as bk,
IF(GROUPING (saler_name, zone_name) = 2, CONCAT(zone_name, "总计"), IFNULL(zone_name, '省区合计')) AS zone_name,
c.position,
saler_name,
-- GROUPING (saler_name, zone_name, c.position),
ROUND(SUM(IF(`use_month` = '1', this_month_sa_money, null)) / 10000, 2) AS month_sa_money_1,
ROUND(SUM(IF(`use_month` = '2', this_month_sa_money, null)) / 10000, 2) AS month_sa_money_2,
ROUND(SUM(IF(`use_month` = '3', this_month_sa_money, null)) / 10000, 2) AS month_sa_money_3,
ROUND(SUM(IF(`use_month` = '4', this_month_sa_money, null)) / 10000, 2) AS month_sa_money_4,
ROUND(SUM(IF(`use_month` = '5', this_month_sa_money, null)) / 10000, 2) AS month_sa_money_5,
ROUND(SUM(IF(`use_month` = '6', this_month_sa_money, null)) / 10000, 2) AS month_sa_money_6,
ROUND(SUM(IF(`use_month` = '7', this_month_sa_money, null)) / 10000, 2) AS month_sa_money_7,
ROUND(SUM(IF(`use_month` = '8', this_month_sa_money, null)) / 10000, 2) AS month_sa_money_8,
ROUND(SUM(IF(`use_month` = '9', this_month_sa_money, null)) / 10000, 2) AS month_sa_money_9,
ROUND(SUM(IF(`use_month` = '10', this_month_sa_money, null)) / 10000, 2) AS month_sa_money_10,
ROUND(SUM(IF(`use_month` = '11', this_month_sa_money, null)) / 10000, 2) AS month_sa_money_11,
ROUND(SUM(IF(`use_month` = '12', this_month_sa_money, null)) / 10000, 2) AS month_sa_money_12,
ROUND(SUM(this_month_sa_money) / 10000, 2) AS year_sa_money
FROM
new_gr_bi_sa_agg_month_count a
LEFT JOIN gr_report.gr_contacts c ON a.saler_name = c.`name`
AND a.zone_name = c.zone
WHERE
use_year = YEAR(CURDATE())
AND sale_type_name = '自营品种'
GROUP BY
zone_name,
saler_name,
c.position WITH ROLLUP
HAVING GROUPING (saler_name, zone_name, c.position) != 1
HAVING GROUPING (saler_name, zone_name, c.position) != 1 ORDER BY a.zone_name DESC, zone_name ASC, c.position IS NULL , c.position DESC
) t
UNION ALL
SELECT