更新:问题似乎已修复,原因是我在声明时使用了不同的小写而不是大写字母。但是,我现在面临的问题是“vw_formdatahard”视图只是填充了多个“NULL”。我在这里疯了。
我有一个程序可以根据Wordpress&中的可用数据创建视图。 Buddypress数据库。这在我的本地Mamp服务器上运行正常,但每当我在托管服务器上调用该过程时都会出错。即使我将整个数据库从本地服务器复制到在线服务器,它也会返回错误。我不是mysql的英雄,所以我在这里走得很远......为什么不运行呢?
以下查询失败:“CALL
stp_FormQueryBuilder
(); MySQL说:#1054 - '字段列表'中的未知列'd.user_id'
BEGIN
DECLARE sqlText text;
DROP VIEW IF EXISTS vw_FormDataRows;
CREATE VIEW vw_FormDataRows AS
SELECT d.user_id, f.name,
CASE WHEN left(f.name, 4) = 'FOTO' && LEFT(d.value, 9) = '/profiles' THEN CONCAT("/wp-content/uploads",d.value)
ELSE d.value END AS 'value'
FROM wp_bp_xprofile_fields AS F
LEFT JOIN wp_bp_xprofile_data AS D ON F.id = D.field_id
WHERE
parent_id = 0
AND group_id = 1
AND d.user_id IN(SELECT U.user_id FROM wp_usermeta AS U WHERE U.meta_key = 'wp_user_level' AND U.meta_value = '0')
ORDER BY d.user_id, f.id;
DROP TEMPORARY TABLE IF EXISTS temp1;
CREATE TEMPORARY TABLE temp1 (SELECT b.user_id, b.name, b.value
FROM (SELECT d.user_id, f.name, d.value
FROM wp_bp_xprofile_fields AS F
LEFT JOIN wp_bp_xprofile_data AS D ON F.id = D.field_id
WHERE
parent_id = 0
AND group_id = 1
AND d.user_id IN(SELECT U.user_id FROM wp_usermeta AS U WHERE U.meta_key = 'wp_user_level' AND U.meta_value = '0')
ORDER BY d.user_id, f.id ) AS B);
SET @sql = NULL;
SET group_concat_max_len = 4096;
SELECT GROUP_CONCAT(DISTINCT
CONCAT('MAX(CASE WHEN name = ', name,
' THEN value END) AS `', replace(name, ' ','_'), '`'))
INTO sqlText
FROM temp1;
DROP VIEW IF EXISTS vw_FormDataHard;
SET @sql = CONCAT('CREATE VIEW vw_FormDataHard AS SELECT user_id, ', sqlText, '
FROM vw_FormDataRows
GROUP BY user_id');
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
DROP TEMPORARY TABLE IF EXISTS temp1;
END
答案 0 :(得分:1)
您从未定义别名d
只是D
,这些是不同的,因为别名区分大小写。
答案 1 :(得分:0)
您声明大写字母“D”并使用小写字母“d” 所以,改变任何一个