有两张表:table1是工资表(编号,年月,....,),
table 是员工表,(编号,姓名 部门)两表主键都是编号.
现在想查询某年某月,某个部门的的数据查询出来,同时把查询出来的数据转存到一个创建的空表(new)里面,
用SQL语句如何将次功能实现,一定要插入到哪个空表里面.
请个位大哥多多指教..谢谢....

解决方案 »

  1.   

    Select * From Table1 into NewTable
      

  2.   

    两表组合查询最好用视图,当然了,也可以联合查询就是用Join,查一下帮助吧
      

  3.   

    我是这样查询
    sql.Add('insert into caozuo1 编号,姓名...)'+
    'select 编号,姓名,from table1,table2);
    但这查询的话.总是出问题...
    所以请说具体点....
      

  4.   

    select * from table1,table where year=?? and bm=??? insert into newtable
      

  5.   

    select a.编号, a.年月, b.部门, sum(a.工资)
    into NewTable
    from Table b left join 
    Table1 a on a.编号 = b.编号
    group by a.编号, a.年月, b.部门
    where...
      

  6.   

    if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[New]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
    drop table [dbo].[New]select t1.编号,t1.年月,t.姓名,t.部门 from table1 t1 where 年月=你的條件
    inner join ( select 姓名,部门 from table ) t 
    on t1.编号=t.编号
      

  7.   

    修改上面的錯誤:
    if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[New]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
    drop table [dbo].[New]select t1.编号,t1.年月,t.姓名,t.部门 into New  from table1 t1 where 年月=你的條件
    inner join ( select 姓名,部门 from table ) t 
    on t1.编号=t.编号
      

  8.   

    thank you !!!
    十分感谢...