select m.username, 
m.jobcount as totalcount,
   (select jobcount from vmonthinsertyes where username=m.username and yearmonth=m.yearmonth) as Yescount,    
   (select jobcount from vmonthinsertno where username=m.username and yearmonth=m.yearmonth) as Nocount,   
   m.yearmonth as jobdate    from vmonth m    where 
   m.operateway='录入'    
   and m.yearmonth>='2004-01'    
   and m.yearmonth<='2005-01'    
   and m.username='lb'

解决方案 »

  1.   

    select m.username, max(m.jobcount) as totalcount,
       max((select jobcount from vmonthinsertyes where username=m.username and yearmonth=m.yearmonth)) as Yescount,    
       max((select jobcount from vmonthinsertno where username=m.username and yearmonth=m.yearmonth)) as Nocount,   
       max(m.yearmonth) as jobdate    from vmonth m    where 
       m.operateway='录入'    
       and m.yearmonth>='2004-01'    
       and m.yearmonth<='2005-01'    
       and m.username='lb'
       group by m.username
      

  2.   

    不好意思上面发错了
    SELECT * FROM

    select m.username AS username , 
           m.jobcount AS totalcount,
          (select jobcount from vmonthinsertyes where username=m.username and yearmonth=m.yearmonth) AS Yescount,    
          (select jobcount from vmonthinsertno where username=m.username and yearmonth=m.yearmonth) AS Nocount,   
           m.yearmonth AS jobdate 
    from vmonth m 
    where m.operateway='录入'    
          and m.yearmonth>='2004-01'    
          and m.yearmonth<='2005-01'    
          and m.username='lb'
    )MSTB
    group by MSTB.username
      

  3.   

    不过个人感觉你这样写出来让大家帮你写有点瞎猜呀,你可以说你的意思大家帮你写!select m.username, sum(m.jobcount) as totalcount,
       sum((select jobcount from vmonthinsertyes where username=m.username and yearmonth=m.yearmonth)) as Yescount,    
       sum((select jobcount from vmonthinsertno where username=m.username and yearmonth=m.yearmonth)) as Nocount,   
       m.yearmonth as jobdate    from vmonth m    where 
       m.operateway='录入'    
       and m.yearmonth>='2004-01'    
       and m.yearmonth<='2005-01'    
       and m.username='lb'
       group by m.username,jobdate;
      

  4.   

    因为我是要修改别人代码,他写的就和 slippers3000的一样,所以弹出“不是GROUP BY 表达式”错误我在后面加了几个group BY但都不对,所以到这里问一下他的作用就是统计用的,其实我们根本都不用管它字段的意义是什么,只是从语法来看的话,它就有问题,我就是不知道问题出在那里