SQL 错误 1064 - MySQL 创建视图时出现问题
SQL error 1064 - MySQL issue creating view
我有这个问题
SET @regex_bl = (SELECT GROUP_CONCAT(DISTINCT word ORDER BY word DESC SEPARATOR '|') FROM t_black_list);
SET @regex_sl = (SELECT GROUP_CONCAT(DISTINCT word ORDER BY word DESC SEPARATOR '|') FROM t_suspect_list);
SELECT
p_f_A.ID,
p_f_A.id_st,
p_f_A.source_query,
p_f_A.st_text,
if (p_f_A.st_image regexp 'http' = 1,p_f_A.st_image,'NO IMAGE') AS st_IMAGE_URL,
if (p_f_A.st_text regexp @regex_bl = 1,'YES','NO') AS BLACK_LIST,
if (p_f_A.st_text regexp @regex_sl = 1,'YES','NO') AS SUSPECT_LIST,
(select f_f_image_recog.TAG from f_f_image_recog WHERE (f_f_image_recog.id_st=p_f_A.ID AND f_f_image_recog.TAG NOT LIKE '%Failure%' ) ORDER BY f_f_image_recog.value DESC LIMIT 1) AS CLARIFAI_1ST_TAG,
(SELECT "X" as X from f_f_tensor_ws WHERE (f_f_tensor_ws.id_st=p_f_A.ID) AND (f_f_tensor_ws.value > 0.98) LIMIT 1 ) AS TS_B_GREEN_LABEL_98,
(SELECT f_f_text_recog.matched_text from f_f_text_recog WHERE (f_f_text_recog.id_st =p_f_A.ID) AND (f_f_text_recog.type LIKE '%Money%') LIMIT 1) AS NLP_MONEY_VALUE,
(SELECT f_f_text_recog.matched_text from f_f_text_recog WHERE (f_f_text_recog.id_st =p_f_A.ID) AND (f_f_text_recog.type LIKE '%Company%') LIMIT 1) AS NLP_COMPANY
from p_f_A
如果我 运行 在我的工具 (HeidiSQL) 的查询框中,一切都按预期工作。
当我尝试创建视图时出现错误:
Errore SQL (1064): You have an error in your SQL syntax; check the
manual that corresponds to your MySQL server version for the right
syntax to use near 'SET @regex_bl = (SELECT GROUP_CONCAT(DISTINCT word
ORDER BY word DESC SEPARATOR ' at line 1
我从你的代码中看不到你是如何声明你的变量的,我只看到你设置了值。这可能会有所不同。
您的问题可能是因为您不能像在存储过程或函数中那样在视图中使用变量。
请参阅以下 post 了解一些选项。
SQL Views - no variables?
尝试从上面引用的 post 中给出这个答案:
CREATE VIEW MyView
AS
WITH MyVars (SomeVar, Var2)
AS (
SELECT
'something' AS 'SomeVar',
123 AS 'Var2'
)
SELECT *
FROM MyTable
WHERE x = (SELECT SomeVar FROM MyVars)
您好,我对查询进行了如下修改,现在可以使用了:
SELECT
p_f_A.ID,
p_f_A.id_st,
p_f_A.source_query,
p_f_A.st_text,
if (p_f_A.st_image regexp 'http' = 1,p_f_A.st_image,'NO IMAGE') AS st_IMAGE_URL,
if (p_f_A.st_text regexp (SELECT GROUP_CONCAT(DISTINCT word ORDER BY word DESC SEPARATOR '|') FROM t_black_list) = 1,'YES','NO') AS BLACK_LIST,
if (p_f_A.st_text regexp (SELECT GROUP_CONCAT(DISTINCT word ORDER BY word DESC SEPARATOR '|') FROM t_suspect_list) = 1,'YES','NO') AS SUSPECT_LIST,
(select f_f_image_recog.TAG from f_f_image_recog WHERE (f_f_image_recog.id_st=p_f_A.ID AND f_f_image_recog.TAG NOT LIKE '%Failure%' ) ORDER BY f_f_image_recog.value DESC LIMIT 1) AS CLARIFAI_1ST_TAG,
(SELECT "X" as X from f_f_tensor_ws WHERE (f_f_tensor_ws.id_st=p_f_A.ID) AND (f_f_tensor_ws.value > 0.98) LIMIT 1 ) AS TS_B_GREEN_LABEL_98,
(SELECT f_f_text_recog.matched_text from f_f_text_recog WHERE (f_f_text_recog.id_st =p_f_A.ID) AND (f_f_text_recog.type LIKE '%Money%') LIMIT 1) AS NLP_MONEY_VALUE,
(SELECT f_f_text_recog.matched_text from f_f_text_recog WHERE (f_f_text_recog.id_st =p_f_A.ID) AND (f_f_text_recog.type LIKE '%Company%') LIMIT 1) AS NLP_COMPANY
from p_f_A
我有这个问题
SET @regex_bl = (SELECT GROUP_CONCAT(DISTINCT word ORDER BY word DESC SEPARATOR '|') FROM t_black_list);
SET @regex_sl = (SELECT GROUP_CONCAT(DISTINCT word ORDER BY word DESC SEPARATOR '|') FROM t_suspect_list);
SELECT
p_f_A.ID,
p_f_A.id_st,
p_f_A.source_query,
p_f_A.st_text,
if (p_f_A.st_image regexp 'http' = 1,p_f_A.st_image,'NO IMAGE') AS st_IMAGE_URL,
if (p_f_A.st_text regexp @regex_bl = 1,'YES','NO') AS BLACK_LIST,
if (p_f_A.st_text regexp @regex_sl = 1,'YES','NO') AS SUSPECT_LIST,
(select f_f_image_recog.TAG from f_f_image_recog WHERE (f_f_image_recog.id_st=p_f_A.ID AND f_f_image_recog.TAG NOT LIKE '%Failure%' ) ORDER BY f_f_image_recog.value DESC LIMIT 1) AS CLARIFAI_1ST_TAG,
(SELECT "X" as X from f_f_tensor_ws WHERE (f_f_tensor_ws.id_st=p_f_A.ID) AND (f_f_tensor_ws.value > 0.98) LIMIT 1 ) AS TS_B_GREEN_LABEL_98,
(SELECT f_f_text_recog.matched_text from f_f_text_recog WHERE (f_f_text_recog.id_st =p_f_A.ID) AND (f_f_text_recog.type LIKE '%Money%') LIMIT 1) AS NLP_MONEY_VALUE,
(SELECT f_f_text_recog.matched_text from f_f_text_recog WHERE (f_f_text_recog.id_st =p_f_A.ID) AND (f_f_text_recog.type LIKE '%Company%') LIMIT 1) AS NLP_COMPANY
from p_f_A
如果我 运行 在我的工具 (HeidiSQL) 的查询框中,一切都按预期工作。 当我尝试创建视图时出现错误:
Errore SQL (1064): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SET @regex_bl = (SELECT GROUP_CONCAT(DISTINCT word ORDER BY word DESC SEPARATOR ' at line 1
我从你的代码中看不到你是如何声明你的变量的,我只看到你设置了值。这可能会有所不同。
您的问题可能是因为您不能像在存储过程或函数中那样在视图中使用变量。
请参阅以下 post 了解一些选项。 SQL Views - no variables?
尝试从上面引用的 post 中给出这个答案:
CREATE VIEW MyView
AS
WITH MyVars (SomeVar, Var2)
AS (
SELECT
'something' AS 'SomeVar',
123 AS 'Var2'
)
SELECT *
FROM MyTable
WHERE x = (SELECT SomeVar FROM MyVars)
您好,我对查询进行了如下修改,现在可以使用了:
SELECT
p_f_A.ID,
p_f_A.id_st,
p_f_A.source_query,
p_f_A.st_text,
if (p_f_A.st_image regexp 'http' = 1,p_f_A.st_image,'NO IMAGE') AS st_IMAGE_URL,
if (p_f_A.st_text regexp (SELECT GROUP_CONCAT(DISTINCT word ORDER BY word DESC SEPARATOR '|') FROM t_black_list) = 1,'YES','NO') AS BLACK_LIST,
if (p_f_A.st_text regexp (SELECT GROUP_CONCAT(DISTINCT word ORDER BY word DESC SEPARATOR '|') FROM t_suspect_list) = 1,'YES','NO') AS SUSPECT_LIST,
(select f_f_image_recog.TAG from f_f_image_recog WHERE (f_f_image_recog.id_st=p_f_A.ID AND f_f_image_recog.TAG NOT LIKE '%Failure%' ) ORDER BY f_f_image_recog.value DESC LIMIT 1) AS CLARIFAI_1ST_TAG,
(SELECT "X" as X from f_f_tensor_ws WHERE (f_f_tensor_ws.id_st=p_f_A.ID) AND (f_f_tensor_ws.value > 0.98) LIMIT 1 ) AS TS_B_GREEN_LABEL_98,
(SELECT f_f_text_recog.matched_text from f_f_text_recog WHERE (f_f_text_recog.id_st =p_f_A.ID) AND (f_f_text_recog.type LIKE '%Money%') LIMIT 1) AS NLP_MONEY_VALUE,
(SELECT f_f_text_recog.matched_text from f_f_text_recog WHERE (f_f_text_recog.id_st =p_f_A.ID) AND (f_f_text_recog.type LIKE '%Company%') LIMIT 1) AS NLP_COMPANY
from p_f_A