dijia_report_data.sql 2.95 KB
-- 追踪器的
SELECT channel as '渠道', settle_merchant as '结算客户',sn as '设备号', settle_time as '结算时间', pk_price as '套餐价格', 
hw_price as '硬件价格', install_price as '安装价格', active_time as '激活时间'  FROM dj_{year}_settle_details where device_type =8 AND settle_time >= '{start_time}' and settle_time < '{end_time}';


-- 记录仪&车充
SELECT channel as '渠道', settle_merchant as '结算客户',sn as '设备号',
case when device_type = 6 then '记录仪' when device_type = 12501 then '车充' end as '设备类型',
settle_time as '结算时间', pk_price as '套餐价格', 
hw_price as '硬件价格', install_price as '安装价格', active_time as '激活时间'  FROM dj_{year}_settle_details_record where settle_time >= '{start_time}' and settle_time < '{end_time}';


-- 退货
SELECT channel as '渠道', settle_merchant as '结算客户',sn as '设备号', 
case when device_type = 8 then '记录仪' when device_type = 6 then '记录仪' when device_type = 12501 then '车充' end as '设备类型',
settle_time as '结算时间', 0-pk_price as '套餐价格', 
0-hw_price as '硬件价格', 0-install_price as '安装价格', active_time as '激活时间'  FROM dj_{year}_settle_details_return where settle_time >= '{start_time}' and settle_time < '{end_time}';

-- 汇总
SELECT channel as '渠道', settle_merchant as '结算客户',sn as '设备号',
'GPS' as '设备类型',
settle_time as '结算时间', pk_price as '套餐价格',
hw_price as '硬件价格', install_price as '安装价格', active_time as '激活时间',cost AS '单位成本',pk_price+hw_price+install_price AS '单价合计',1 AS '硬件数量','追踪器明细' AS '来源'
FROM dj_{year}_settle_details where device_type =8 AND settle_time >= '{start_time}' and settle_time < '{end_time}'
UNION
SELECT channel as '渠道', settle_merchant as '结算客户',sn as '设备号',
case when device_type = 6 then '记录仪' when device_type = 12501 then '车充' end as '设备类型',
settle_time as '结算时间', pk_price as '套餐价格',
hw_price as '硬件价格', install_price as '安装价格', active_time as '激活时间',cost AS '单位成本',pk_price+hw_price+install_price AS '单价合计',1 AS '硬件数量','记录仪明细' AS '来源'
FROM dj_{year}_settle_details_record where settle_time >= '{start_time}' and settle_time < '{end_time}'
UNION
SELECT channel as '渠道', settle_merchant as '结算客户',sn as '设备号',
case when device_type = 8 then 'GPS' when device_type = 6 then '记录仪' when device_type = 12501 then '车充' end as '设备类型',
settle_time as '结算时间', 0-pk_price as '套餐价格',
0-hw_price as '硬件价格', 0-install_price as '安装价格', active_time as '激活时间',cost AS '单位成本',(0-pk_price)+(0-hw_price)+(0-install_price) AS '单价合计',-1 AS '硬件数量','退货明细' AS '来源'
FROM dj_{year}_settle_details_return WHERE settle_time >= '{start_time}' and settle_time < '{end_time}'