我的目标是在表格中显示来自DOC_sql和MDT_sql的数据。找不到关于如何实施这种联系的解决方案。
目标是搜索文档并根据匹配的标签显示文档。
输入数据
CALL SearthDocuments('\'Book\',\'Currency\'', 'en_ENG');
代码
DELIMITER //
CREATE PROCEDURE SearthDocuments(IN VAR_TT_names VARCHAR(255), VAR_LANG_prefix CHAR(6))
BEGIN
SET @TT_sql = CONCAT('SELECT TAG_ID FROM TagTranslate WHERE TT_text IN (', VAR_TT_names, ')');
SET @DOC_ID_sql = CONCAT('SELECT DOC_ID FROM DocumentTag WHERE TAG_ID IN (', @TT_sql, ') GROUP BY DOC_ID HAVING COUNT(DOC_ID)');
SET @DOC_sql = CONCAT('SELECT * FROM VIEW_Document WHERE DOC_ID IN (', @DOC_ID_sql, ') AND LANG_prefix = "', VAR_LANG_prefix, '"' );
SET @MDT_sql = CONCAT('SELECT DOC_ID, count(*) as TAG_HITS FROM DocumentTag WHERE TAG_ID IN (', @TT_sql, ') GROUP BY DOC_ID HAVING COUNT(DOC_ID)');
-- SET @COM_sql = CONCAT('?')
-- PREPARE COM_stmt FROM @COM_sql;
-- EXECUTE COM_stmt;
-- DEALLOCATE PREPARE COM_stmt;
END
// DELIMITER ;
两个表都有标识符DOC_ID
表:DOC_sql
DOC_ID, DT_ID, DT_desc, DT_title, A_name, LANG_prefix
表:MDT_sql
DOC_ID, TAG_HITS
答案 0 :(得分:0)
这是问题的解决方案。工作代码。
ID DAY TYPE_ID TYPE NUM START_DATE END_DATE
---- --------- ------- ---- ---- --------- ---------
4241 15/09/15 2 1 66 01/01/00 31/12/99
4241 16/09/15 2 1 66 01/01/00 31/12/99
4241 17/09/15 9 1 59 17/09/15 18/09/15
4241 18/09/15 9 1 59 17/09/15 18/09/15
4241 19/09/15 2 1 66 01/01/00 31/12/99
4241 20/09/15 2 1 66 01/01/00 31/12/99
4241 15/09/15 3 2 63 01/01/00 31/12/99
4241 16/09/15 8 2 159 16/09/15 17/09/15
4241 17/09/15 8 2 159 16/09/15 17/09/15
4241 18/09/15 3 2 63 01/01/00 31/12/99
4241 19/09/15 3 2 63 01/01/00 31/12/99
4241 20/09/15 3 2 63 01/01/00 31/12/99
2134 15/09/15 2 1 66 01/01/00 31/12/99
2134 16/09/15 2 1 66 01/01/00 31/12/99
2134 17/09/15 9 1 59 17/09/15 18/09/15
2134 18/09/15 9 1 59 17/09/15 18/09/15
2134 19/09/15 2 1 66 01/01/00 31/12/99
2134 20/09/15 2 1 66 01/01/00 31/12/99
2134 15/09/15 3 2 63 01/01/00 31/12/99
2134 16/09/15 8 2 159 16/09/15 17/09/15
2134 17/09/15 8 2 159 16/09/15 17/09/15
2134 18/09/15 3 2 63 01/01/00 31/12/99
2134 19/09/15 3 2 63 01/01/00 31/12/99
2134 20/09/15 3 2 63 01/01/00 31/12/99