随笔分类 -  数据库及SQL

摘要:1.distinct去重 注意的点:distinct 只能一列去重,当distinct后跟大于1个参数时,他们之间的关系是&&(逻辑与)关系,只有全部条件相同才会去重 弊端:当查询的字段比较多时,distinct会作用多个字段,导致去重条件增多 select distinct UserResult 阅读全文
posted @ 2023-04-07 19:04 golandhome 阅读(602) 评论(0) 推荐(0) 编辑
摘要:摘自:https://www.cnblogs.com/guorongtao/p/11939751.html 1、正常循环语句 declare @orderNum varchar(255) create table #ttableName(id int identity(1,1),Orders var 阅读全文
posted @ 2023-04-07 19:01 golandhome 阅读(4731) 评论(0) 推荐(0) 编辑
摘要:STUFF():在 SQL Server 中,stuff() 函数用于从源字符串中删除给定长度的字符序列,并从指定的起始索引插入给定的字符序列。 用法: STUFF (source_string, start, length, change_string) source_string:字符数据 st 阅读全文
posted @ 2023-04-07 19:00 golandhome 阅读(4484) 评论(0) 推荐(0) 编辑
摘要:select stuff((select ','+title from tb for xml path('')),1,1,'') --其中tb是表名,title是要合并的表中的字段名称 阅读全文
posted @ 2023-04-07 18:59 golandhome 阅读(26) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示