大家好,又见面了,我是你们的朋友全栈君。
SET @EE = '';
SET @str_tmp = '';
SET @Revenue_JSON = '';
SET @Revenue_JSON_tmp = '';
SELECT @EE := CONCAT(
@EE,
'SUM(IF(fsRevenueTypeName=\'',
fsRevenueTypeName,
'\'',
',fdSubTotal,0)) AS ''revenue_',
fsRevenueTypeName,
''','
) AS aa ,
@Revenue_JSON := CONCAT (
@Revenue_JSON,','',"'
,fsRevenueTypeName,'":'','
,'revenue_',fsRevenueTypeName
)
AS bb
INTO @str_tmp,@Revenue_JSON_tmp
FROM
(
SELECT DISTINCT
fsRevenueTypeName
FROM
TempRevenueType
WHERE fsRevenueTypeName IS NOT NULL
) A
ORDER BY
LENGTH(aa) DESC
LIMIT 1;
-- 拼接 json
SELECT CONCAT('''{',SUBSTRING(@Revenue_JSON_tmp,4),','',"汇总":'',','revenue_汇总',',''}''') INTO @Revenue_JSON_tmp;
SET @QQ = CONCAT(
' CREATE TEMPORARY TABLE TempRevenueType1 ( SELECT fsSellNo3,CONCAT(',@Revenue_JSON_tmp,') as revenue_info',
' FROM ( SELECT fsSellNo as fsSellNo3,',@str_tmp,
' SUM(fdSubTotal) AS revenue_汇总 FROM TempRevenueType Group By fsSellNo) a );'
);
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/137507.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...