我有两张表:
newstype_t:id name
newsInfo_t:id name type
我想实现这一的效果:就是在现实类型的时候现实每种类型包含的数量,showType.jsp
id   name   num
1    公告   5
2    新闻   10
这应该怎么实现……
用数据库语言load出来,但是load出来是一张表,但是我不知道怎么才能把类型和数量对应起来……

解决方案 »

  1.   

    select a.name,b.num from newstype_t a
    left join (
        select count(*) as num,type from newsInfo_t group by type
    ) b
    left join a.id = b.typetype存的是newstype_t表id吧
      

  2.   

    select a.name,b.num from newstype_t a
    left join (
        select count(*) as num,type from newsInfo_t group by type
    ) b
    on a.id = b.type 刚写错了
      

  3.   

    select t.id,t.name,count(i.id) from newstype_t t,newsInfo_t i where t.id=i.type group by t.id,t.name;
    假设这里newsInfo_t的type存的是newstype_t的id。
      

  4.   

    相对应的hql语句应该怎么写呢?有谁帮帮忙……