#Table A(RoomId,CurrentPeoNum)(房间id,当前人数)
表A里有如下数据
1 0
2 0
3 0
4 0#TableB(RecordId,RoomId)(id,房间id"外键")
1 1
2 1
3 2
4 3
5 3
6 3
我通过分组(Roomid)可以得到
Roomid count(*)
1 2
2 1
3 3
怎么把我分组后得到记录更新到#TableA中去
#TableA 后的记录为
RoomId CurrentPeoNum
1 2
2 1
3 3
4 0
该怎么写啊?现在这儿谢谢大家了!
表A里有如下数据
1 0
2 0
3 0
4 0#TableB(RecordId,RoomId)(id,房间id"外键")
1 1
2 1
3 2
4 3
5 3
6 3
我通过分组(Roomid)可以得到
Roomid count(*)
1 2
2 1
3 3
怎么把我分组后得到记录更新到#TableA中去
#TableA 后的记录为
RoomId CurrentPeoNum
1 2
2 1
3 3
4 0
该怎么写啊?现在这儿谢谢大家了!
解决方案 »
- 急求一个通配符查询的写法
- sql2005本地订阅的问题
- 100分求一高效的语句(或方法)
- 急,char(5)字段aaa 尾部要加00 这句怎么写 aaa字段的值有 010 、 120 这样?
- 请教需用触发器检查插入的值,比较的难哦!
- SSIS有Foreach批量导入数据,想获取数据的文件名称,好像要用变量什么的怎么弄?
- SQLSERVER2000中货币数据的表示问题?
- 【请教】请教一个SQL语句,关于职位和公司的查询
- SQL Server:在单机上作开发,如果不用网卡......
- 很菜的问题,请指教。我的sqlserver数据库连接不上?
- 这句SQL怎么写?好急!!!
- ◆◆◆从30多万数据记录中提取 47 个记录,竟然花了 276 秒!!!无法忍受!怎么调整?◆◆◆
insert into @t select 1,0
union all select 2,0
union all select 3,0
union all select 4,0declare @a table(RecordId int,RoomId int)
insert into @a select 1,1
union all select 2,1
union all select 3,2
union all select 4,3
union all select 5,3
union all select 6,3update a set CurrentPeoNum=b.cnt from @t a,(select Roomid,count(*) as cnt from @a group by Roomid) b where a.Roomid=b.Roomidselect * from @t