select type,count(*) 总次数,(select count(*) from t2 where type=t1.type) 维修次数 from t1 group by type

解决方案 »

  1.   

    '喝醉了
      select type
             ,count(*) 总次数
             ,(select count(*) from t2 where type=t1.type) 维修次数 
        from t1 
    group by type
      

  2.   

    如果是现在情况怎么办?t1为车型表:      id   type(车型)
                字段为1     a
                      2     b
                      3     c
                      ...
    t2为维修表:time    no(车牌)(维修信息:车牌和时间)
                 1     a1
                 2     a1
                 3     b1
                 ...
    t3为车辆信息表: id  no   type(某辆车对应某个车型)
                     1   a1   a
                     2   b1   b
                     3   a1   a
                     ...   
    现在我要统计各车型的维修次数和总次数,而且车型是可能增加的,t2的数据是不停增多的,还要加入time的限定,如:5>time>2,如何组织语句?谢谢