标签:des style blog http color os ar for sp
需求:
一张表是APP表,结构如下:
app_category为该游戏所属的类别ID,xml字段类型
另一张表是类别表,就ID对应名称,这就不上图了。
还有一张表是每个游戏的下载记录,结构如下:
DownLogs_APPId为对应的游戏
那么需求来了,要查询游戏的下载记录,查询字段中要有游戏的所属类别名称,多个用逗号分隔
查询结果应如下:
最终的执行语句如下:
select APP_Id,APP_Name,LEFT(App_Category,len(App_Category)-1) as App_Category,DownLogs_IMEI,DownLogs_AddTime from ( select APP_Id,APP_Name,( select Category_Title+‘,‘ from tbl_Category where Category_Id in(select T.C.value(‘.‘,‘nvarchar(5)‘) as ss from tbl_APP as app cross apply app.APP_Category.nodes(‘/id‘) as T(C) where app_id=tbl_DownLogs.APP_Id) for xml path(‘‘)) as App_Category, DownLogs_IMEI,DownLogs_AddTime from ( select APP_Id,APP_Name,APP_Category,DownLogs_IMEI,DownLogs_AddTime from tbl_APP right join tbl_Download_Logs on tbl_APP.APP_Id= tbl_Download_Logs.DownLogs_APPId ) as tbl_DownLogs ) as T
下面一步步分解
No.1
标签:des style blog http color os ar for sp
原文地址:http://www.cnblogs.com/New-world/p/4036849.html