两张表 1. 用户表 user 表结构 userid     name   address    phone 
    
       2. 收费信息表 sfxx 表结构 userid name address feiyong(费用) sfrq(收费日期)  sfnd(收费年度) 
我现在需要找出某个收费年度如2008年度未缴费的用户,并生成一个欠费用户表qfuser 表结构同user 。
我想用存储过程,但不太会,希望大家多帮忙,先谢谢啦。                   

解决方案 »

  1.   

    select a.*
    from user a
    where not exists(select 1 from sfxx where userid = a.userid and sfnd = 2008')
      

  2.   

    select * 
    from [user]
    where userid not in(
        select userid 
        from sfxx 
        where feiyong>0 
          and sfnd=2008)
      

  3.   

    select * 
    into qfuser --生成表
    from [user]
    where userid not in(
        select userid 
        from sfxx 
        where feiyong>0 
          and sfnd=2008)
      

  4.   


    select a.* into qfuser 
    from [user] a
    where not exists(select 1 from sfxx where userid = a.userid and sfnd = 2008')
      

  5.   


    select * 
    from [user]
    where userid in(
        select userid 
        from sfxx 
        where feiyong>0 
          and sfnd=2008
          and sfrq is null )我们大家的思路,取决于你收费的时候修改哪个字段
    如果你收费的时候输入收费日期的话,那么这个答案是正确的
      

  6.   

    create proc taoistong_2008
    as select * 
    from [user]
    where userid in(
        select userid 
        from sfxx 
        where feiyong>0 
          and sfnd=2008
          and sfrq is null )