SQL.Text := 'select U.areaname, U.houseno, U.houseunit, U.housing, '
      + 'U.chargingarea, U.name, U.telephone,U.meterno,U.readmeterno, '
      + 'D.headtotal, D.coldtotal, U.memo'
      + 'from TB_USERINFO as U, TB_USERDATATEMP as D '
      + 'where U.meterno=D.meterno';这是一个查询语句,我想把从二个表里取出的数据存到第三个表里,表的名称是TB_USERTOTAL,而且里面还有二个字段是分别对:D.headtotal, D.coldtotal这二个字段乘上一个单价分别是headprice和coldprice得到D.headmoney, D.coldmoney,请问这个SQL语句怎么处理?

解决方案 »

  1.   

    表结构都不说 怎么帮你写SQL
      

  2.   

    headprice,coldprice在哪里?这样?      insert into TB_USERTOTAL
          select U.areaname, U.houseno, U.houseunit, U.housing,
          U.chargingarea, U.name, U.telephone,U.meterno,U.readmeterno,
          D.headtotal,D.headtotal*headprice headmoney, D.coldtotal,D.coldtotal*coldprice coldmoney, U.memo
          from TB_USERINFO as U, TB_USERDATATEMP as D
          where U.meterno=D.meterno
      

  3.   

    Insert Into TABLE Select .. from 
      

  4.   

    SQL.Text := 'insert into TB_USERTOTAL '
          + 'select U.areaname, U.houseno, U.houseunit, U.housing, ' 
          + 'U.chargingarea, U.name, U.telephone,U.meterno,U.readmeterno, ' 
          + 'D.headtotal, D.coldtotal, U.memo' 
          + 'from TB_USERINFO as U, TB_USERDATATEMP as D ' 
          + 'where U.meterno=D.meterno'; 
      

  5.   

    headprice,coldprice这二个是临时变量。谢谢楼上的几位!
      

  6.   

    SQL.Text := 'insert  TB_USERTOTA(reaname, houseno, houseunit, housing, ' 
          + 'chargingarea, name, telephone,meterno,readmeterno, ' 
          + 'headtotal, coldtotal, memo)
          + 'select U.areaname, U.houseno, U.houseunit, U.housing, ' 
          + 'U.chargingarea, U.name, U.telephone,U.meterno,U.readmeterno, ' 
          + 'D.headtotal, D.coldtotal, U.memo' 
          + 'from TB_USERINFO as U, TB_USERDATATEMP as D ' 
          + 'where U.meterno=D.meterno';