有四张表
comment 评论表 inforId为信息id
information 信息表 id为主键 ,title为标题 ,userid为用户id ,sortid为分类id
user 用户信息 userid为主键 name为用户名
sort 分类信息表 sortid为主键 sortName为类型名查询出某个用户的发布信息的评论信息:其中包括信息标题(title)用户名name 类型名sortName 信息的评论次数请大虾们多多的指教谢谢!

解决方案 »

  1.   

    select a.title ,b.name , c.sortname  ,count(*) [次数]from 
    information a join user b on a.userid =b.userid join sort c on a.sortid =c.sortid
    join comment d on a.userid = d.userid 
    group by a.title ,b.name , c.sortname
      

  2.   

    不不不,修改如下
    declare @userid int
    set @userid = 'your_uerid'select a.title ,b.name , c.sortname  ,count(*) [次数]
    from information a join user b on a.userid =b.userid join sort c on a.sortid =c.sortid join comment d on a.userid = d.userid 
    where a.userid = @userid
    group by a.id
      

  3.   

    create table comment(inforid int,detail nvarchar(1000))
    create table information(id int,title nvarchar(100),userid int,sortid int)
    create table [user](userid int,name nvarchar(10))
    create table sort(sortid int,sortname nvarchar(10))insert into information select 1,'title1',1,1
                  union all select 2,'title2',1,2
                  union all select 3,'title3',2,3
                  union all select 3,'title4',1,3insert into comment select 1,'mytitle1'
              union all select 1,'mytitle2'
              union all select 2,'mytitle3'
              union all select 3,'mytitle3'
              union all select 4,'mytitle4'insert into [user] select 1,'usera'
             union all select 2,'userb'insert into sort select 1,'sortname1'
           union all select 2,'sortname2'
           union all select 3,'sortname3'
    select a.title,c.name,d.sortname,count(b.inforid) from information a
    inner join comment b on b.inforid=a.id
    inner join [user]  c on c.userid=a.userid and c.userid=1
    inner join sort    d on d.sortid=a.sortid
    group by a.title,c.name,d.sortname
    drop table comment,information,[user],sort
    ------------------------------title1 usera sortname1 2
    title2 usera sortname2 1
    title4 usera sortname3 1
      

  4.   

    我觉得评论表中还应该有评论内容、用户id等啊,
    就像CSDN这的,你信息表中应该存的相当于这的楼主提出的问题吧,评论表中应该存对于信息表中信息id的评论内容,跟是谁评论的!略表意见!!