BBS中父模块缩进,子模块归属父模块的实现方式

板块显示顺序问题

在tbl_board表中增加一个显示顺序字段 order

alter table tbl_board
add ( order_num number(3) );

update tbl_board set order_num = 20 where boardname = '.NET技术';

update tbl_board set order_num = 21 where boardname = 'C#语言';
update tbl_board set order_num = 22 where boardname = 'WinForms';
update tbl_board set order_num = 23 where boardname = 'ADO.NET ';
update tbl_board set order_num = 24 where boardname = 'ASP.NET ';

update tbl_board set order_num = 10 where boardname = 'Java技术';

update tbl_board set order_num = 11 where boardname = 'Java基础';
update tbl_board set order_num = 12 where boardname = 'JSP技术 ';
update tbl_board set order_num = 13 where boardname = 'Servlet技术 ';
update tbl_board set order_num = 14 where boardname = 'Eclipse应用';

update tbl_board set order_num = 30 where boardname = '数据库技术';

update tbl_board set order_num = 31 where boardname = 'Oracle ';
update tbl_board set order_num = 32 where boardname = 'SQL Server';

update tbl_board set order_num = 40 where boardname = '娱乐';
update tbl_board set order_num = 41 where boardname = '灌水乐园';

commit;

-------------------------------------------------------------------------

清单查询sql

select b.boardname , nvl(t1.topic_count , 0) as topic_count , t2.title , t2.uname , t2.publishtime
from tbl_board  b
left join ( select boardid , count(*) as topic_count from tbl_topic group by boardid ) t1 on b.boardid = t1.boardid
left join (
 select boardid ,title , uname , publishtime
 from tbl_topic t21
 join tbl_user u on t21.userid = u.userid
 where publishtime = (
  select max(publishtime)
  from tbl_topic t22
  where t22.boardid = t21.boardid
 )
) t2  on b.boardid = t2.boardid
order by b.order_num;

原文地址:https://www.cnblogs.com/moonfans/p/2700613.html