表 oa_com_account  字段  account(姓名) ,accountid(姓名id)表 oa_com_worklog  字段 accountid,titles,contens
要求产生的查询结果
姓名    日志记录总数
**      *
**      *
...     ....

解决方案 »

  1.   

    select a.account as 姓名,
    count(1) as 日志记录总数
    from oa_com_account a left join oa_com_worklog b
    on a.accountid=b.accountid
    group by a.account
      

  2.   

    select a.account,isnull(count(b.accountid),0) total
    from oa_com_account a
      left outer join oa_com_worklog b
         on a.accountid=b.accountid
      

  3.   

    select   a.account,t.cnt from oa_com_account as a,
    (select  accountid,count(*) as cnt from oa_com_worklog group by accountid) as t
    where a.accountid=t.accountid
      

  4.   

    更正
    select a.account as 姓名,
    count(b.accountid) as 日志记录总数
    from oa_com_account a left join oa_com_worklog b
    on a.accountid=b.accountid
    group by a.account
      

  5.   


    select m.account 姓名 , isnull(n.cnt , 0 ) 日志记录总数 from oa_com_account m
    left join
    (select accountid , count(*) cnt from oa_com_worklog group by accountid) n
    on m.accountid = n.accountid
    group by m.accountid
      

  6.   

    2楼漏了..select a.account,isnull(count(b.accountid),0) total
    from oa_com_account a
      left outer join oa_com_worklog b
         on a.accountid=b.accountid
    group by a.account
      

  7.   

    select m.account 姓名 , isnull(count(*) , 0 ) 日志记录总数 from oa_com_account m
    left join oa_com_worklog n
    on m.accountid = n.accountid
    group by m.accountid