首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

插入多行数据解决方案

2012-01-19 
插入多行数据表1Recordsidobjectidcostunitiddates1a900.8xx2007-1-12a800.8xx2007-1-23b700.7xx2007-1-34

插入多行数据
表1   Records  
    id     objectid       cost     unitid     dates
      1             a             900.8       xx       2007-1-1
      2             a             800.8       xx       2007-1-2
      3             b             700.7       xx       2007-1-3
      4             b             600.8       xx       2007-1-7
表2   budget
      id       objectid       unit       money  
要将表1中的   objectid   unitid   sum(cost)按objectid分组插入到表2中

string   strSQL   =   "insert   into     budget   (objectid,unit_id,money)   select   Records.objectid,Records.unitid,(sum(Records.cost))   as   mon   from   Records   where   Recordes.unitid= 'xx '   group   by   Records.objectid   ";
这个语句正确吗?为什么不能插入到budget中.


[解决办法]
insert into budget(objectid,unitid,money) select objectid,unitid,sum(cost) as money from Records group by objectid,unitid

热点排行
Bad Request.