目前我有四个表,
company: id,name
type:id,name
status:id,name
project:id,company_id,type_id,status_id,name现在TYPE和status中预制了0和1进去,
我需要的到的结果是
每个COMPANY下面的记录对应的project记录数,type各个类型的project记录数,status为1的各type的project记录数.
大概就是如下的一显示字段:商铺名称   
总记记录数量  
type为1的记录数量变  
type为2的记录数量 
status为1(type为1的数量)  
status为1(type为2的数量)

解决方案 »

  1.   

    select c.name,
    count(*) as totalCnt,
    sum(if(p.type_id=1,1,0)) as type1Cnt,
    sum(if(p.type_id=2,1,0)) as type2Cnt,
    sum(if(p.type_id=1 and p.status_id=1,1,0)) as type1St1Cnt,
    sum(if(p.type_id=2 and p.status_id=1,1,0)) as type1St1Cnt
    from ((company as c inner join project as p on c.id=p.company_id)
    inner join type as t on p.type_id=t.id)
    inner join status as s on p.status_id=s.id.
        [align=center]====  ====
    [/align]
    .
    贴子分数<20:对自已的问题不予重视。
    贴子大量未结:对别人的回答不予尊重。
    .