Files
youlegames/codes/games/sql/game/scripts/transfer_detail.sql

47 lines
2.2 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
-- ============================================================
-- 脚本名称: transfer_detail.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
t.from_sales AS '发卡代理ID',
su_from.saus_nickname AS '发卡代理昵称',
t.satr_salesid AS '接收代理ID',
su_to.saus_nickname AS '接收代理昵称',
t.satr_amount AS '转卡数量',
DATE_FORMAT(t.satr_transfertime, '%Y-%m-%d %H:%i:%s') AS '转卡时间'
FROM
sales_transferbill t
LEFT JOIN sales_user su_to
ON t.satr_agentid = su_to.saus_agentid
AND t.channel_id = su_to.saus_channelid
AND t.satr_salesid = su_to.saus_salesid
LEFT JOIN sales_user su_from
ON t.satr_agentid = su_from.saus_agentid
AND t.from_sales = su_from.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
ORDER BY
t.satr_transfertime ASC;