❶ sql 怎么将一列中的数据按一个分隔符分成多列显示
withHrmResource(id,lastname)as(
select167,'段秋月'unionall
select170,'杨子军'
)
,formtable_main_78(Requestid,WTCW,XMCY)as(
select722,'xxxxx公司','167,170'
)
selecta.*,stuff(c.[col],1,1,'')[项目名称]
fromformtable_main_78a
crossapply
(select','+lastnamefromHrmResourceb
wherecharindex(','+convert(varchar,b.id)+',',','+a.XMCY+',')>0
forxmlpath(''))c([col])
结果:
❷ sql 怎么总金额合计拆分成多列 比如合计由三个组成,‘“100”,“200”,“300”,这
你这个没办法拆分的,首先,按照你的说法,这部分是没有规律的。假如说我拆成200,200,200也行啊。是不是,没有一定的规律怎么拆分。
如果你原来显示的是100,200,300,,那你计算完sum后,在后面在写上这些字段就好了,如果有什么具体要求,还是要写详细的,现在你的这种说法只能说,不可能,因为拆的方式(100,200,300)(200,200,200)太多了,怎么拆啊。
❸ sql数据库按符号拆分成多列和多行
你这样是把列2看成是一个多值数据了,用普通的sql是处理不了的。用plsql写个小过程来做很容易啊,把一行数据读出来,然后对列2进行逐个字符读取放到临时字符,遇到换行的就把列1和临时字符写到数据库,然后继续读
❹ SQLsever management 一列拆分为多列
假设原来的列名为column1
Select
Substring(Column1,1,2) as Num1,
Substring(Column1,4,2) as Num2,
Substring(Column1,7,2) as Num3,
Substring(Column1,10,2) as Num4,
Substring(Column1,13,2) as Num5,
Substring(Column1,16,2) as Num6,
Substring(Column1,19,2) as Num7
From
table
❺ 在SQL中如何把一列字符串拆分为多列,请高手
--首先,你是按什么规则拆? 我举个例子 你要按字段中的逗号拆开,假设字段名叫text--用charindex和substring这2个函数 select substring(text,1,charindex(',',text)-1) as [before], substring(text,charindex(',',text),len(text)) as [after] from table
❻ SQL逗号分割一列数据的值,将结果变成一行多列
createtable#t(IDint,Contentvarchar(4000))
insertinto#t(ID,Content)
select1,'22,5000,3000'
unionallselect2,'1,35,200,2'
unionallselect3,'802,22'
unionallselect4,'213,354,2002,22,500'
select*from#t
declare@sqlnvarchar(4000),@iint
set@i=1
whileexists(select1from#twhereContent<>'')
begin
set@sql='altertable#taddPKQ'+convert(varchar,@i)+'int'
exec(@sql)
set@sql='declare@locintupdate#tset@loc=charindex('','',Content),PKQ'
+convert(varchar,@i)+'=convert(int,case@locwhen0thenContentelse'
+'substring(Content,1,@loc-1)end),Content=case@locwhen0then''''else'
+'substring(Content,@loc+1,len(Content)-@loc)endwhereContent<>'''''
exec(@sql)
set@i=@i+1
end
select*from#t
❼ mysql中将一列以逗号分隔的值分割成多列显示
可以用
SUBSTRING
_INDEX()函数
在mysql中提供了一些
字符串操作
的函数,其中SUBSTRING_INDEX(str,
delim,
count)
str:
要处理的字符串
delim:
分割符
count:
计数
如果为正数,则从左开始数,如果为负数,则从右开始数
❽ sql 一列如何按条件分成多列
------------------------------------------------------------------------
-- author:jc_liumangtu(【DBA】小七)
-- date: 2010-03-26 09:37:30
-- version:
-- Microsoft SQL Server 2005 - 9.00.1399.06 (Intel X86)
-- Oct 14 2005 00:33:37
-- Copyright (c) 1988-2005 Microsoft Corporation
-- Developer Edition on Windows NT 5.1 (Build 2600: Service Pack 3)
--
------------------------------------------------------------------------use test
set nocount on
if object_id('test4','U') is not null
drop table test4
go
create table test4
(item int ,date char(8),type char(2),quty int)
insert into test4
select 1000 , '20100101', 'A' , 100 union all
select 2000 , '20100101' ,'B' , 200 union all
select 1000 , '20100101' ,'C' , 100 union all
select 2000 , '20100101' , 'D' , 100
select * from test4select item ,date
,max(case type when 'A' then quty else 0 end) [typeA]
,max(case type when 'B' then quty else 0 end) [typeB]
,max(case type when 'C' then quty else 0 end) [typeC]
,max(case type when 'D' then quty else 0 end) [typeD]
from test4 group by item,date
item date type quty
----------- -------- ---- -----------
1000 20100101 A 100
2000 20100101 B 200
1000 20100101 C 100
2000 20100101 D 100item date typeA typeB typeC typeD
----------- -------- ----------- ----------- ----------- -----------
1000 20100101 100 0 100 0
2000 20100101 0 200 0 100
❾ 在SQL中怎么把一列字符串拆分为多列,请高手赐教
--首先,你是按什么规则拆?我举个例子你要按字段中的逗号拆开,假设字段名叫text
--用charindex和substring这2个函数
selectsubstring(text,1,charindex(',',text)-1)as[before],substring(text,charindex(',',text),len(text))as[after]fromtable
❿ 在sql中如何把一列的值拆分成多列,求高手指教
其实可以理解为,多列取同一个字段的值。