id type value1 value2
1 1 1 1
1 2 2 2
2 1 3 3
2 2 4 4 把ID相同的行 value1值相加 value2值相加并更新type=2的行 并删除type=1的行 想要的结果
id type value1 value2
1 2 3 3
2 2 7 7
1 1 1 1
1 2 2 2
2 1 3 3
2 2 4 4 把ID相同的行 value1值相加 value2值相加并更新type=2的行 并删除type=1的行 想要的结果
id type value1 value2
1 2 3 3
2 2 7 7
解决方案 »
- 帮忙个看下!!!!Internet explorer 无法打开Internet站点
- 三层架构的查询问题。
- 怎么在后台设置Calendar显示的日期?
- arraylist绑定的数据通过checkbox的选择动态删除记录
- 请问:在GridView1_RowDataBound()事件中如何获取当前行的表Id值?
- 求一个好一些的翻页
- 浏览器的进度条问题
- 请问应该怎么把一个string类转换成stream类
- 我对重写URL的理解,望高手指正.(有代码)
- 在datagrid的一个label控件中,可不可以对取到的值用一个函数进行处理后,再显示???
- 请问如何用JS把gridview下的checkbox都readonly
- 断点设置 单步调试
insert into @t values(1 , 1 , 1 , 1 )
insert into @t values(1 , 2 , 2 , 2 )
insert into @t values(2 , 1 , 3 , 3 )
insert into @t values(2 , 2 , 4 , 4 )update @t set value1 = a.value1 , value2 = a.value2 from(
select [id],sum(value1) as value1 , sum(value2) as value2 from @t group by [id] having count(*)=2) a
inner join @t b on b.[id] = a.[id] and type =2delete from @t where [id] in( select [id] from @t group by [id] having count(*)=2) and type = 1 select * from @t
insert into @t values(1 , 1 , 1 , 1 )
insert into @t values(1 , 2 , 2 , 2 )
insert into @t values(2 , 1 , 3 , 3 )
insert into @t values(2 , 2 , 4 , 4 )update @t set value1 = a.value1 , value2 = a.value2 from(
select [id],sum(value1) as value1 , sum(value2) as value2 from @t group by [id] having count(*)=2) a
inner join @t b on b.[id] = a.[id] and type =2delete from @t where [id] in( select [id] from @t group by [id] having count(*)=2) and type = 1 select * from @t
declare @t table([id] int, type int, value1 int, value2 int)
insert into @t values(1 , 1 , 1 , 1 )
insert into @t values(1 , 2 , 2 , 2 )
insert into @t values(2 , 1 , 3 , 3 )
insert into @t values(2 , 2 , 4 , 4 )update @t set value1 = a.value1 , value2 = a.value2 from(
select [id] , 2 as type , sum(value1) as value1 , sum(value2) as value2 from @t group by [id] having Count(*)>1)a
inner join @t b on b.[id] = a.[id] and b.[type] =2 delete from @t where type='1' and [id] in( select [id] from @t group by [id] having Count(*)>1)select * from @t
where [id]=@IDdelete from tableName where [id]=@ID and type=1update tableName set value1=(select value1 from #t where id=@id),
value2=(select value2 from #t where id=@id)
where [id]=@ID
select id,max(type) as type , sum(value1) as value1 ,sum(value2) as value2 from table1 group by id order by id
insert into @t values(1 , 1 , 1 , 1 )
insert into @t values(1 , 2 , 2 , 2 )
insert into @t values(2 , 1 , 3 , 3 )
insert into @t values(2 , 2 , 4 , 4 )
SELECT
ID,
MAX(TYPE)TYPE,
SUM(VALUE1)VALUE1,
SUM(value2)value2
FROM
@T
GROUP BY
ID
(所影响的行数为 1 行)
(所影响的行数为 1 行)
(所影响的行数为 1 行)
(所影响的行数为 1 行)ID TYPE VALUE1 value2
----------- ----------- ----------- -----------
1 2 3 3
2 2 7 7(所影响的行数为 2 行)