其中一张用户yh表,另一张记录jl表。yh表上有用户名yhm用户号yhh等信息。jl表上有某用户的多条记录信息jlxx,和用户号yhh,两个表都通过yhh字段相连。求所有用户的平均是多少条记录?还有不清楚的吗?

解决方案 »

  1.   

    select avg(jl.jlxx) ,yh.yhh
    from yh , jl
    where yh.yhh = jl.yhh
    group by yh.yhh 
      

  2.   

    我可能搞错题意了select avg(a.totaljlxx) /*所有用户的平均*/
    from (
    select count(jl.jlxx) totaljlxx ,yh.yhh /*每个用户的平均*/
    from yh , jl
    where yh.yhh = jl.yhh
    group by yh.yhh )a
      

  3.   

    select avg(convert(float,a.totaljlxx)) /*所有用户的平均*/
    from (
    select count(jl.jlxx) totaljlxx ,yh.yhh /*每个用户的平均*/
    from yh , jl
    where yh.yhh = jl.yhh
    group by yh.yhh )a