请问各位高手:下面这条语句运行不成功,如果换成on a.user_id=b.user_id就成功,但是不是我想要的结果
select a.document_types,count(b.document_types) from gss_documen_cate a left join gss_documentation b on a.document_types=b.document_types where a.user_id=18 group by a.document_types;

解决方案 »

  1.   

    select a.document_types,count(b.document_types)
    from gss_documen_cate a left join (select document_types from gss_documentation where user_id=18) b
        on a.document_types=b.document_typesselect document_types,(select count(*) from gss_documentation where user_id=18)
    from gss_documen_cate
      

  2.   

     a.document_types=b.document_types 两个表中documentation表中有的type而a表没有因为你是left join 所以 不会查出所有的type