新增数据库相关语句脚本
This commit is contained in:
49
codes/games/sql/game/scripts/transfer_summary.sql
Normal file
49
codes/games/sql/game/scripts/transfer_summary.sql
Normal file
@@ -0,0 +1,49 @@
|
||||
-- ============================================================
|
||||
-- 脚本名称: transfer_summary.sql
|
||||
-- 功 能: 指定年月的转卡汇总报表(按下级代理分组,含合计行)
|
||||
-- 数据库 : agent_db
|
||||
-- 用 法:
|
||||
-- 1. 修改下方【参数设置】中的变量值
|
||||
-- 2. 在 Navicat 中执行全部脚本
|
||||
-- 3. 结果集右键 → Export → Excel 可导出表格
|
||||
-- ============================================================
|
||||
|
||||
|
||||
-- ============================================================
|
||||
-- 【参数设置】 ← 修改这里
|
||||
-- ============================================================
|
||||
SET @p_year = 2026; -- 年份
|
||||
SET @p_month = 3; -- 月份(1-12)
|
||||
SET @p_from_sales = 10437216; -- 发卡来源代理ID(上级代理)
|
||||
SET @p_agent_id = 'veRa0qrBf0df2K1G4de2tgfmVxB2jxpv'; -- 代理商ID
|
||||
|
||||
|
||||
-- ============================================================
|
||||
-- 【汇总报表】按下级代理分组,最后一行为转卡总计
|
||||
-- ============================================================
|
||||
SELECT
|
||||
IF(
|
||||
GROUPING(t.satr_salesid),
|
||||
'★ 合计',
|
||||
CAST(t.satr_salesid AS CHAR)
|
||||
) AS '代理ID',
|
||||
IF(
|
||||
GROUPING(t.satr_salesid),
|
||||
'—',
|
||||
MAX(su.saus_nickname)
|
||||
) AS '代理昵称',
|
||||
COUNT(t.idx) AS '转卡次数',
|
||||
SUM(t.satr_amount) AS '转卡总量'
|
||||
FROM
|
||||
sales_transferbill t
|
||||
LEFT JOIN sales_user su
|
||||
ON t.satr_agentid = su.saus_agentid
|
||||
AND t.channel_id = su.saus_channelid
|
||||
AND t.satr_salesid = su.saus_salesid
|
||||
WHERE
|
||||
t.satr_agentid = @p_agent_id
|
||||
AND t.from_sales = @p_from_sales
|
||||
AND YEAR(t.satr_transfertime) = @p_year
|
||||
AND MONTH(t.satr_transfertime) = @p_month
|
||||
GROUP BY
|
||||
t.satr_salesid WITH ROLLUP;
|
||||
Reference in New Issue
Block a user