Suppose I got a table with emails and category and I want to group the emails based on category, the following sql statement can be simply be used:
DECLARE @Email AS TABLE
(
Category INT,
Email VARCHAR(MAX)
)
INSERT INTO @Email
SELECT DISTINCT te.Category,
(
SELECT Email + ','
FROM @TempEmail te2
WHERE te2.Category = te.Category
ORDER BY Email
FOR XML PATH('')
) AS Email
FROM @TempEmail te
本文介绍了一种使用SQL声明表格并根据类别对电子邮件进行分组的方法。通过创建一个临时表格并插入唯一类别与对应的电子邮件,可以有效地管理和组织大量电子邮件。
1810

被折叠的 条评论
为什么被折叠?



