MYSQL版本问题导致SQL语法错误!unknow column 'SQLSTR'
SQLSTR是别名,在MySQL5.7以上版本能通过,在5.0上提示unknow column ‘SQLSTR’错误,我不知道应该怎么修改(因为客户关系不能通过mysql版本),请各位大神指点!
BEGIN
DECLARE sTYPE VARCHAR(20);
DROP TEMPORARY TABLE IF EXISTS temp_public_data;
CREATE TEMPORARY TABLE temp_public_data SELECT
DATE_FORMAT(FROM_UNIXTIME(n.inputtime),'%Y-%m-%d') as days,
DATE_FORMAT(FROM_UNIXTIME(n.inputtime),'%Y-%m') as months,
DATE_FORMAT(FROM_UNIXTIME(n.inputtime),'%Y') as years,
DATE_FORMAT(FROM_UNIXTIME(n.inputtime),'%u') as weeks,
count(n.id) as pubnum,n.username from v9_news as n
WHERE DATE_FORMAT(FROM_UNIXTIME(n.inputtime),'%Y-%m-%d') BETWEEN pDayBegin AND pDayEnd
GROUP BY days,n.username;
IF pType=1 THEN
SET sType = "years";
ELSEIF pType=2 THEN
SET sType = "months";
ELSEIF pType=3 THEN
SET sType = "weeks";
ELSEIF pType=5 THEN
SET sType = "days";
END IF;
SET @EE = "";
SELECT @EE:= CONCAT(@EE,',SUM(IF(username=\'',username,'\',pubnum,0)) AS \'',username,'\'') AS **SQLSTR** FROM (SELECT DISTINCT username FROM temp_public_data) A ORDER BY **LENGTH(SQLSTR)** DESC LIMIT 0,1;
SET @SQL = CONCAT('SELECT IFNULL(',sType,',\'TOTAL\') AS MONTH');
SET @SQL = CONCAT(@SQL,@EE);
SET @SQL = CONCAT(@SQL,',SUM(pubnum) as TOTAl ');
SET @SQL = CONCAT(@SQL,' FROM temp_public_data');
SET @SQL = CONCAT(@SQL,' GROUP BY ',sType,' WITH ROLLUP;');
#SELECT @SQL;
PREPARE stmt FROM @SQL;
EXECUTE stmt;
DROP TEMPORARY TABLE IF EXISTS temp_public_data;
END
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可以了,用SQLSTR后面into 一个变量,然后用这个变量来order就可以了,汗!