Write a SQL XML Field association query once

Source: Internet
Author: User

Demand:

A table is an app table with the following structure:

  

App_category The Category Id,xml field type to which the game belongs

Another table is the category table, which corresponds to the name of the ID, which is not.

There is also a table for each game download record, the structure is as follows:

  

Downlogs_appid for the corresponding game

Then the demand comes, to query the game's download record, the query field to have the game's category name, multiple separated by commas

The query results should be as follows:

The final execution statement is as follows:

SelectAPP_ID,app_name, Left(App_category,Len(app_category)-1) asApp_category,downlogs_imei,downlogs_addtime from (SelectAPP_ID,app_name,(        SelectCategory_title+','  fromTbl_categorywherecategory_idinch(SelectT.c.value ('.','nvarchar (5)') asSs fromTbl_app asApp CrossApply App. App_category.nodes ('/id') asT (C)whereapp_id=TBL_DOWNLOGS.APP_ID) forXML Path ("')) asapp_category, Downlogs_imei,downlogs_addtime from (    SelectAPP_ID,app_name, App_category,downlogs_imei,downlogs_addtime fromTbl_app Right JoinTbl_download_logs onTbl_app. app_id=tbl_download_logs.downlogs_appid) astbl_downlogs) asT

The following step-by-step decomposition

The

Write a SQL XML Field association query once

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.