In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
Today I'll show you how SQL Server merges strings in a group. The content of the article is good. Now I would like to share it with you. Friends who feel in need can understand it. I hope it will be helpful to you. Let's read it along with the editor's ideas.
SELECT p2.G
SS = JSON_VALUE (
REPLACE (
(SELECT _ = p1.s FROM T p1 WHERE p1.G = p2.G FOR JSON PATH)
,'"}, {" _ ":',','),'$[0]. _'
)
FROM T p2
SQL Server 2014 requires three layers of nesting to merge strings within a group, and with XML, the code looks very complex:
SELECT Main.G
LEFT (Main.SS,Len (Main.SS)-1) As "SS"
FROM
(
SELECT DISTINCT p2.G
(
SELECT p1.s +','AS [text ()]
FROM T p1
WHERE p1.G = p2.G
ORDER BY p1.G
FOR XML PATH ('')
) [SS]
FROM T p2
) [Main]
Although other versions of SQL Server are written differently, they are usually very complicated.
When the database does not have a function like group_concat, it can be implemented with the help of esProc, and the code will be much simpler. Also for SQL Server,esProc version 2014, you can merge strings in the group as follows:
AB1=db.query ("select G, S from T") / query from SQL Server 20142=A1.group (G;. (s) .concat (",") / merge lines with commas
In this way, you can achieve functions similar to group_concat, and can be used on any database.
EsProc is a scripting language that can be executed repeatedly in IDE and can also be called on the command line, which is suitable for simplifying the difficulties in SQL.
This is how SQL Server merges all the strings in the group. For more information about how SQL Server merges strings in the group, you can search for previous articles or browse the following articles to learn! I believe the editor will add more knowledge to you. I hope you can support it!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.