遇到一个麻烦的问题,求存储过程
有4个表
bbs_board bbs_thread bbs_topic bbs_count
-----------------------------------------------
bbs_board 结构
id(论坛ID) boardname(论坛名) ...
1 论坛1
-------------------------------
bbs_thread 结构
threadid(主题ID) boardid(论坛ID) ...
3 1
-------------------------------
bbs_topic 结构
topicid(帖子ID) threadid(主题ID) ...
5 3
-------------------------------
bbs_count 结构
total id boardname
(统计结果) (论坛id) (论坛名)
-----------------------------------------------
对应关系 bbs_board.id = bbs_thread.boardid
bbs_thread.threadid = bbs_topic.threadid
---------------------------------------------------------
现在要分别统计不同论坛的帖子数并插入到bbs_count表,就是统计bbs_topic.topicid
结果为
bbs_count
total id boardname
100 1 论坛1
200 2 论坛2
150 3 论坛3
问题点数:50、回复次数:3Top
1 楼wangtiecheng(不知不为过,不学就是错!)回复于 2006-03-09 19:44:26 得分 50
insert into bbs_count(total,id,boardname)
select count(*) as bbs_count,a.id,a.boardname
from bbs_board a
inner join bbs_thread b on a.id = b.boardid
inner join bbs_topic c b.threadid = c.threadid
group by a.id,a.boardname
order by a.id,a.boardname
Top
2 楼Nils(睡瞌睡等机会)回复于 2006-03-09 19:58:46 得分 0
只执行里面的select
抱错
消息 102,级别 15,状态 1,第 4 行
'b' 附近有语法错误。Top
3 楼wangtiecheng(不知不为过,不学就是错!)回复于 2006-03-09 20:03:12 得分 0
--sorry,少了个on
insert into bbs_count(total,id,boardname)
select count(*) as bbs_count,a.id,a.boardname
from bbs_board a
inner join bbs_thread b on a.id = b.boardid
inner join bbs_topic c on b.threadid = c.threadid
group by a.id,a.boardname
order by a.id,a.boardname
/*
create table #bbs_board (id int,boardname varchar(100))
create table #bbs_thread(threadid int,boardid int)
create table #bbs_topic(topicid int,threadid int)
create table #bbs_count(total int,id int,boardname varchar(100))
insert into #bbs_count(total,id,boardname)
select count(*) as bbs_count,a.id,a.boardname
from #bbs_board a
inner join #bbs_thread b on a.id = b.boardid
inner join #bbs_topic c on b.threadid = c.threadid
group by a.id,a.boardname
order by a.id,a.boardname
drop table #bbs_board,#bbs_thread,#bbs_topic,#bbs_count
*/
Top




