要用到group,count这样的东西。不过你要做这样的东西,不管是access还是sql server,都应该从视图(查询)设计器上入手,可以可视化的编辑。

解决方案 »

  1.   

    1
    select a.pc,a.srs 计划招生数,b.sc 已招生数,(case when a.srs>b.sc then a.src-b.sc else 0 end) 未完成数
    from (select pc,sum(rs) as srs from jh group by pc) a left join
    (select pc,count(*) sc from lq group by pc) b on a.pc=b.pc
    order by a.pc2select (select xxmc from xxdm where xxdm=a.xxdm), 
    a.pc,a.srs 计划招生数,b.sc 已招生数,(case when a.srs>b.sc then a.src-b.sc else 0 end) 未完成数
    from (select xxdm,pc,sum(rs) as srs from jh group by xxdm,pc) a left join
    (select xxdm,pc,count(*) sc from lq group by xxdm,pc) b on a.pc=b.pc and a.xxdm=b.xxdm
    order by a.xxdm,a.pc
      

  2.   

    2select (select xxmc from xxdm where xxdm=a.xxdm) xxmc, 
    a.pc,a.srs 计划招生数,b.sc 已招生数,(case when a.srs>b.sc then a.src-b.sc else 0 end) 未完成数
    from (select xxdm,pc,sum(rs) as srs from jh group by xxdm,pc) a left join
    (select xxdm,pc,count(*) sc from lq group by xxdm,pc) b on a.pc=b.pc and a.xxdm=b.xxdm
    order by xxmc,a.pc
      

  3.   

    我用的是VFP做的单机版,没有用到SQL SERVER,但我喜欢用SQL语句代替传统的VFP语句,将来移植也比较容易。
    明年会移到SQL Server上,今年时间来不及了。
    谢谢楼上的两位,我试一下,回头来给分。
      

  4.   

    试了一下,在VFP下的SQL格式不支持:(
    总是通不过,用ansi sql可能会好的
    有别的方法吗?谢谢
      

  5.   

    1
    select a.pc,a.srs 计划招生数,b.sc 已招生数,a.src-b.sc  未完成数
    from (select pc,sum(rs) as srs from jh group by pc) a left join
    (select pc,count(*) sc from lq group by pc) b on a.pc=b.pc
    order by a.pc
    2select (select xxmc from xxdm where xxdm=a.xxdm) xxmc, 
    a.pc,a.srs 计划招生数,b.sc 已招生数,a.src-b.sc 未完成数
    from (select xxdm,pc,sum(rs) as srs from jh group by xxdm,pc) a left join
    (select xxdm,pc,count(*) sc from lq group by xxdm,pc) b on a.pc=b.pc and a.xxdm=b.xxdm
    order by xxmc,a.pc