select
a.主题,
count(b.帖子编号) as 所含帖子数量
from
theme as a inner join article as b on a.theme=b.theme
group by
a.主题
a.主题,
count(b.帖子编号) as 所含帖子数量
from
theme as a inner join article as b on a.theme=b.theme
group by
a.主题
解决方案 »
- sql server2005 数据类型的疑问
- 继续问傻问题 exec()
- 每个字段给一个索引名跟几个字段共用一个索引名称有区别吗?
- 求救:sql server里用户自定义的函数为什么不能调用exec语句?
- 求SQL语句
- 插入数据时的触发器,请大侠帮帮忙!!!高分请教!!!!
- 请教一条查询语句?
- 蛙蛙请教:在sqlserver里如何查询保存在Text类型字段里的xml格式文本的特定节点文本
- SQL SEVER 怎么取三列数据的最大者
- sql server 有一个表 创建好视图,在添加字段,在查询试图,没有结果
- vs2010 '-' 附近有语法错误。但是找不到“-”在哪一行
- 两张表对多个字段比较的SQL求助
就是每一次增加或或者删除一篇帖子article,然后theme表中的article的数目就相应增加或者减少1。
一定要的话可以用下面的 create trigger tr_article
on article
after insert,delete,update
as begin
update a set article_num=isnull(b.[count],0)
from theme a
join (select theme,count(article) as [count] from article
group by theme) b on a.theme=b.theme
where a.articel_num<>isnull(b.[count],0)
end
on article
after insert
as
begin
declare @num = select article_num
from theme
update theme
set article_num= @num+1
endcreate trigger tr_add_article -- 删除
on article
after Delete
as
begin
declare @num = select article_num
from theme
update theme
set article_num= @num-1
end
create trigger tr_del_article -- 删除
名字忘了改了