www.dbpj.net > sql语句查出多行数据,如何将ID相同的行并成一行,...

sql语句查出多行数据,如何将ID相同的行并成一行,...

select distinct 字段 from 表名

select id, max(case when rn = 1 then op end ) op_1, max(case wehn rn = 1 then result end ) result_1, max(case when rn = 1 then else end ) else_1, max(case when rn = 2 then op end ) op_2, max(case wehn rn = 2 then result end ) result_2, max(

--sql2000Create Function fn_hb(@id Varchar(100))Returns Varchar(8000)AsBeginDeclare @Rst Varchar(8000)Set @Rst=''Select @Rst=@Rst+name+',' From test Where id=@idSet @Rst=Left(@Rst,len(@RSt)-1)Return @RstEndgo--调用select

很简单,同一个表两个id关联,用连接符||就行.select a.id,a.name||b.namefrom table a,table bwhere a.id=b.id

SELECT * FROM (SELECT T.ID, LEAD(T.NAME, 0, '') OVER(PARTITION BY T.ID ORDER BY T.ID), LEAD(T.NAME, 1, '') OVER(PARTITION BY T.ID ORDER BY T.ID), LEAD(T.NAME, 2, '') OVER(PARTITION BY T.ID ORDER BY T.ID), ROW_NUMBER() OVER(PARTITION BY T.ID ORDER BY T.ID) AS ROWC FROM TAC T) WHERE ROWC = 1;看看这个是不是你要的~

select id ,time,sum(2),sum(3),sum(4) from 表group by id,timeorder time如果time 不是字符类型分组分的不对可以直接转成字符类型到天再用

sql语句如何合并相同id下的多行数据在一行 例如: 匿名 分享到微博 提交回答 1 问: 所有服务器都 数据操纵语句有哪些? 回答 2 3 多条查询语句查出来的字段是一样的 各取前n条记录并合并数据

mssql下create Table #myfal (ID int,data1 varchar(20),data2 varchar(20))insert into #myfal values (1,1,'')insert into #myfal values (1,1.1,'')insert into #myfal values (1,'',0.3)insert into #myfal values (2,1,'')insert into #myfal values (2,'',1.2)select * from #

group by 前面相同的字段,后面不同的,用max取.SELECT m.member_id, prefix_desc 'Prefix:', UPPER(first_name) 'First Name:', UPPER(last_name) 'Last Name:', UPPER(email) 'Email:', LOWER(user_id) 'User ID:', REPLICATE('*',LEN(

用游标declare @id varchar(50)declare @id1 varchar(150)declare @int intdeclare cursor1 cursor for --定义游标cursor1select UserName from dbo.GoodsPinglun where GoodID='20092170' --使用游标的对象(跟据需要填入select文)set @id1=''

网站地图

All rights reserved Powered by www.dbpj.net

copyright ©right 2010-2021。
www.dbpj.net内容来自网络,如有侵犯请联系客服。zhit325@qq.com