当前位置: 代码迷 >> Sql Server >> 请看瞥这个sql语句
  详细解决方案

请看瞥这个sql语句

热度:2   发布时间:2016-04-24 10:03:58.0
请看看这个sql语句
insert into hfgl_Hffpd(comname,tasktypename,sendman,activitynumber,zysj,createtime,Customername,address,
phonenumber,custermercode,tasktype)
select top 30 percent * from(
SELECT ROW_NUMBER() OVER(ORDER BY z.createtime DESC) AS ROWNUM,
cp.comname,dt.tasktypename,t.sendman,t.taskcode,z.zysj,z.createtime,c.customername,c.address,c.phonenumber,
c.customercode,dt.tasktype 
from zyhd_gdrqjmdhZyd z
LEFT JOIN task t ON z.rwdid=t.id
LEFT JOIN customer c ON t.customerid=c.ID
left join company cp on t.recievecom=cp.id
join dic_tasktype dt on t.tasktypeid=dt.tasktype
where 1=1)h where datediff(dd,h.createtime,getdate())=2
------解决方案--------------------
INSERT  INTO hfgl_Hffpd
        ( comname ,
          tasktypename ,
          sendman ,
          activitynumber ,
          zysj ,
          createtime ,
          Customername ,
          address ,
          phonenumber ,
          custermercode ,
          tasktype
        )
        SELECT TOP 30 PERCENT
           comname ,
          tasktypename ,
          sendman ,
          activitynumber ,
          zysj ,
          createtime ,
          Customername ,
          address ,
          phonenumber ,
          custermercode ,
          tasktype
        FROM    ( SELECT    ROW_NUMBER() OVER ( ORDER BY z.createtime DESC ) AS ROWNUM ,
                            cp.comname ,
                            dt.tasktypename ,
                            t.sendman ,
                            t.taskcode ,
                            z.zysj ,
                            z.createtime ,
                            c.customername ,
                            c.address ,
                            c.phonenumber ,
                            c.customercode ,
                            dt.tasktype
                  FROM      zyhd_gdrqjmdhZyd z
                            LEFT JOIN task t ON z.rwdid = t.id
                            LEFT JOIN customer c ON t.customerid = c.ID
                            LEFT JOIN company cp ON t.recievecom = cp.id
  相关解决方案