|
本帖最后由 李维强-15级 于 2018-6-8 00:35 编辑
SELECT top 20 * FROM (
SELECT ArticleId,Title1,b.AuthorName,PostTime,'article' as srcType,'' as test
from t_d_article a INNER JOIN t_d_author b ON a.AuthorId=b.AuthorId
where a.IsDelete<>1 AND Title1 LIKE '%法%'
UNION
SELECT a.pictureid,a.name,b.AuthorName,PostTime,'picture',''
FROM t_d_picture a INNER JOIN t_d_author b ON a.AuthorId=b.AuthorId
where a.IsDelete<>1 AND Name LIKE '%法%'
UNION
SELECT splistid,title,b.authorname,posttime,'SP' as srcType,''
FROM t_d_SPList a INNER JOIN t_d_author b ON a.AuthorId=b.AuthorId
where a.Title LIKE '%法%'
UNION
--作者
SELECT ArticleId,Title1,b.AuthorName,PostTime,'article',''
from t_d_article a INNER JOIN t_d_author b ON a.AuthorId=b.AuthorId
where a.IsDelete<>1 AND b.AuthorName LIKE '%法%'
UNION
SELECT a.pictureid,a.name,b.AuthorName,PostTime,'picture',''
FROM t_d_picture a INNER JOIN t_d_author b ON a.AuthorId=b.AuthorId
where a.IsDelete<>1 AND b.AuthorName LIKE '%法%'
UNION
SELECT splistid,title,b.authorname,posttime,'SP',''
FROM t_d_SPList a INNER JOIN t_d_author b ON a.AuthorId=b.AuthorId
where b.AuthorName LIKE '%法%'
--关键词
UNION
SELECT b.ArticleId,c.Title1,d.AuthorName,c.PostTime,'article' as srcType,''
FROM t_d_keyword a INNER JOIN t_d_KWRelation b ON a.KeyWordId=b.KeyWordId
INNER JOIN t_d_article c ON c.ArticleId=b.ArticleId
INNER JOIN t_d_author d ON c.AuthorId=d.AuthorId
where a.Name like '%法%' AND a.type=1
) AS s
GROUP BY Articleid,title1,authorname,posttime,srctype,test
ORDER BY posttime DESC
SELECT REPLACE((SELECT STUFF((SELECT name FROM t_d_keyword where Name like '%法%' for xml path('')),1,0,'')),'<name>','')
以下为最终版,关键是 LIKE '%法%'-----------------------------------------------------------------
SELECT top 20 * FROM (
SELECT a.ArticleId,Title1,b.AuthorName,PostTime,'article' as srcType,
REPLACE((SELECT STUFF((SELECT name FROM t_d_keyword x INNER JOIN t_d_KWRelation y ON x.KeyWordId=y.KeyWordId where y.ArticleId=a.ArticleId for xml path('')),1,0,'')),'<name>','') as kw
from t_d_article a INNER JOIN t_d_author b ON a.AuthorId=b.AuthorId
where a.IsDelete<>1 AND Title1 LIKE '%法%'
UNION
SELECT a.pictureid,a.name,b.AuthorName,PostTime,'picture' as srcType,
REPLACE((SELECT STUFF((SELECT name FROM t_d_keyword x INNER JOIN t_d_KWRelation y ON x.KeyWordId=y.KeyWordId where y.PictureId=a.PictureId for xml path('')),1,0,'')),'<name>','') as kw
FROM t_d_picture a INNER JOIN t_d_author b ON a.AuthorId=b.AuthorId
where a.IsDelete<>1 AND Name LIKE '%法%'
UNION
SELECT splistid,title,b.authorname,posttime,'SP' as srcType,''
FROM t_d_SPList a INNER JOIN t_d_author b ON a.AuthorId=b.AuthorId
where a.Title LIKE '%法%'
UNION
--作者
SELECT a.ArticleId,Title1,b.AuthorName,PostTime,'article' as srcType,
REPLACE((SELECT STUFF((SELECT name FROM t_d_keyword x INNER JOIN t_d_KWRelation y ON x.KeyWordId=y.KeyWordId where y.ArticleId=a.ArticleId for xml path('')),1,0,'')),'<name>','') as kw
from t_d_article a INNER JOIN t_d_author b ON a.AuthorId=b.AuthorId
where a.IsDelete<>1 AND b.AuthorName LIKE '%法%'
UNION
SELECT a.pictureid,a.name,b.AuthorName,PostTime,'picture' as srcType,
REPLACE((SELECT STUFF((SELECT name FROM t_d_keyword x INNER JOIN t_d_KWRelation y ON x.KeyWordId=y.KeyWordId where y.PictureId=a.PictureId for xml path('')),1,0,'')),'<name>','') as kw
FROM t_d_picture a INNER JOIN t_d_author b ON a.AuthorId=b.AuthorId
where a.IsDelete<>1 AND b.AuthorName LIKE '%法%'
UNION
SELECT splistid,title,b.authorname,posttime,'SP' as srcType,''
FROM t_d_SPList a INNER JOIN t_d_author b ON a.AuthorId=b.AuthorId
where b.AuthorName LIKE '%法%'
--关键词
UNION
SELECT b.ArticleId,c.Title1,d.AuthorName,c.PostTime,'article' as srcType,
REPLACE((SELECT STUFF((SELECT name FROM t_d_keyword x INNER JOIN t_d_KWRelation y ON x.KeyWordId=y.KeyWordId where y.ArticleId=b.ArticleId for xml path('')),1,0,'')),'<name>','') as kw
FROM t_d_keyword a INNER JOIN t_d_KWRelation b ON a.KeyWordId=b.KeyWordId
INNER JOIN t_d_article c ON c.ArticleId=b.ArticleId
INNER JOIN t_d_author d ON c.AuthorId=d.AuthorId
where a.Name like '%法%' AND a.type=1
UNION
SELECT b.pictureid,c.name,d.AuthorName,c.PostTime,'picture' as srcType,
REPLACE((SELECT STUFF((SELECT name FROM t_d_keyword x INNER JOIN t_d_KWRelation y ON x.KeyWordId=y.KeyWordId where y.PictureId=b.PictureId for xml path('')),1,0,'')),'<name>','') as kw
FROM t_d_keyword a INNER JOIN t_d_KWRelation b ON a.KeyWordId=b.KeyWordId
INNER JOIN t_d_picture c ON c.pictureid=b.pictureid
INNER JOIN t_d_author d ON c.AuthorId=d.AuthorId
where a.Name like '%法%' AND a.type=2
) AS s
GROUP BY Articleid,title1,authorname,posttime,srctype,kw
ORDER BY posttime DESC
|
|