日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

SQL Server使用 LEFT JOIN ON LIKE进行数据关联查询

發布時間:2025/3/15 数据库 18 豆豆
生活随笔 收集整理的這篇文章主要介紹了 SQL Server使用 LEFT JOIN ON LIKE进行数据关联查询 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

這是來新公司寫的第一篇文章,使用LEFT JOIN ON LIKE處理一下這種問題:

SQL視圖代碼如下:

CREATE View [dbo].[VI_SearchCN] AS --搜索產品的文件 ( select upload.FileId as ID,upload.Name as Title,upload.Name as FileTxt,con.TypeId as TypeId,upload.Path as DownLoadPath, '文件' as SearchType,'0' as CategoryId,'0' as ParentCategoryId,upload.Sort,upload.CreateDate from Whir_Ext_Upload upload left join Whir_U_Content con on ('*'+con.FileDownload+'*') like ('%*'+upload.Path+'*%') where con.FileDownload!='' and con.IsDel=0 and con.TypeId=2 ) UNION ALL --搜索產品 ( select con.Whir_U_Content_PId as ID,con.Title, '' as FileTxt, con.TypeId,'' as DownLoadPath,'產品' as SearchType,CategoryId,cat.ParentId as ParentCategoryId,con.Sort,con.CreateDate from Whir_U_Content Con LEFT JOIN Whir_U_Content_Category Cat ON Cat.Whir_U_Content_Category_PId=con.CategoryIdwhere con.TypeId=2 and con.IsDel=0 ) UNION ALL --新聞 select Whir_U_Content_PId as ID,Title,'' as FileTxt,TypeId,'' as DownLoadPath,'新聞' as SearchType,'0' as CategoryId,'0' as ParentCategoryId,Sort,CreateDate from Whir_U_Content where TypeId IN (13,14,15) and IsDel=0 UNION ALL ( --文件下載COA --select Whir_U_Content_PId as ID,Title,TypeId,'' as DownLoadPath,'COA' as SearchType,Sort,CreateDate from Whir_U_Content where TypeId=35 and IsDel=0 select upload.FileId as ID,con.Title,upload.Name as FileTxt,con.TypeId as TypeId,upload.Path as DownLoadPath, 'COA' as SearchType,'0' as CategoryId,'0' as ParentCategoryId,con.Sort,con.CreateDate from Whir_Ext_Upload upload left join Whir_U_Content con on ('*'+con.FileDownload+'*') like ('%*'+upload.Path+'*%') where con.FileDownload!='' and con.IsDel=0 and con.TypeId=35 )GO

前端代碼如下:

<wtl:list ID="mylist1" needpage="true" sql="select ID,Title,Filetxt,TypeId,DownLoadPath,SearchType,CategoryId,ParentCategoryId,CreateDate from VI_SearchCN where Title LIKE '%{0}%' order by Sort desc,CreateDate desc" sql0="{@key,false}"><wtl:if testtype="{$SearchType}" TestOperate="IN" testvalue="文件,COA"><successTemplate><dd><a href="{$uploadpath}{$DownLoadPath,parent,1}" download="{$Title,parent,1}"><span title="{$Title,70,parent,1}">【{$SearchType,parent,1}】{$Title,70,parent,1}</span><time>{$CreateDate,yyyy.MM.dd,parent,1}</time></a></dd></successTemplate></wtl:if><wtl:if testtype="{$SearchType}" TestOperate="Equals" testvalue="新聞"><successTemplate><dd><a href="{$syspath}news/info_{$TypeId,parent,1}.aspx?itemid={$ID,parent,1}"><span title="{$Title,70,parent,1}">【{$SearchType,parent,1}】{$Title,70,parent,1}</span><time>{$CreateDate,yyyy.MM.dd,parent,1}</time></a></dd></successTemplate></wtl:if><wtl:if testtype="{$SearchType}" TestOperate="Equals" testvalue="產品"><successTemplate><dd><a href="{$syspath}cpzx/info_{$TypeId,parent,1}.aspx?itemid={$ID,parent,1}&lcid={$CategoryId,parent,1}&bcid={$ParentCategoryId,parent,1}"><span title="{$Title,70,parent,1}">【{$SearchType,parent,1}】{$Title,70,parent,1}</span><time>{$CreateDate,yyyy.MM.dd,parent,1}</time></a></dd></successTemplate></wtl:if></wtl:list>

?

轉載于:https://www.cnblogs.com/kongxiaoshuang/p/8797119.html

總結

以上是生活随笔為你收集整理的SQL Server使用 LEFT JOIN ON LIKE进行数据关联查询的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。