T1:
bbsid user neirong count
1122 aa 吃饭去了 0T2
REID bbsid replay
1 1122 什么时候回来啊
2 1122 马上回来
主要功能就是为了统计贴子的回复数目 ,类似于CSDN,
t2表贴子有几条回复数,就在T1表count相加数目,如现在上表,现在COUNT应该是2用触发器吗?怎么写?
bbsid user neirong count
1122 aa 吃饭去了 0T2
REID bbsid replay
1 1122 什么时候回来啊
2 1122 马上回来
主要功能就是为了统计贴子的回复数目 ,类似于CSDN,
t2表贴子有几条回复数,就在T1表count相加数目,如现在上表,现在COUNT应该是2用触发器吗?怎么写?
解决方案 »
- SQL SERVER 中如何查询字段是AABB 或者是AAA这样的值?
- 可以从A表的字段内容复制到B表的某字段内容去吗?
- 分库数据同步的问题
- 统计的问题,帮我看看可以实现吗?
- 如何用语句一次清理SQL中一个数据库的日志文件内容.
- 统计 ,再开一次!
- 求助,诚心求教 SQL查询问题
- 存储过程output变量值突然全变成0的疑惑,大虾们进来帮帮小弟
- 一笑而过??vfp是怎么搞的?用了read events 也不行?急!!!!!!!
- torn page error,用sp_dboptiion 设为false,问题依然,请高手指点,急!!!!
- DOS攻击
- 有什么好办法将"2008-09-05 下午 01:02:06" 格式转为 2008-09-05 13:02:06
on t2
for insert
as
begin
update a set a.count=b.count
from t1 a join (
select bbsid,count(*) as count from inserted group by bbsid
)b on a.bbsid=b.bbsid
end
select count(*) from t2 where bbsid=t.bbsid
)
from t1 t
那这有两个t from t1 t bbsid=t.bbsid
select count(*) from t2 where bbsid=t1.bbsid
) from t1运行提示:"from附件有语法错误" "count附件有语法错误"
on t2
for insert
as
begin
update a set a.count=b.count
from t1 a join (
select bbsid,count(*) as count from inserted group by bbsid
)b on a.bbsid=b.bbsid
end
完全可以
declare @t1 table (bbsid int ,[user] nvarchar(10),neirong nvarchar(10),count int)
insert into @t1 select 1122,'aa','吃饭去了',0
select * from @t1
declare @t2 table (reid int,bbsid int,replay nvarchar(10))
insert into @t2 select 1,1122,'什么时候回来啊'
union all select 2,1122,'马上回来'
update a set a.[count]=b.[count] from @t1 a join
(select t2.bbsid,COUNT(*) as [count] from @t2 t2 join @t1 as t1 on t2.bbsid=t1.bbsid
group by t2.bbsid) as b on a.bbsid=b.bbsid
select * from @t1
------
1122 aa 吃饭去了 2
------