0

我将一些数据从 csv 文件导出到 R。我正在使用 sqldf 包更新数据。我的以下查询运行。我可以提供我的 csv 文件,但我不知道如何在此处附加文件:(

> sqldf("select * from
+ (
+  
+ select Disposition as dummy_disposition, case Disposition
+ when 'Disposition' then  'UNKNOWN'
+ when 'Donate' then  'EOL'
+ when 'Resale' then  'EOL'
+ when 'Harvest' then  'EOL'
+ when 'IntelSpinOff' then  'EOL'
+ when 'Scrap' then  'EOL'
+ when 'BufferFeedForward' then   'ACTIVE'
+ when 'FB' then  'UNKNOWN'
+ when 'Unknown' then  'UNKOWN'
+ when 'HarvestResale' then  'EOL'
+ when 'ReturnToSupplier' then  'EOL'
+ when 'IcapResale' then  'EOL'
+ when 'NonEmsManaged' then  'EOL'
+ when 'BufferEOL' then  'EOL'
+ when 'ResaleScrap' then  'EOL'
+ when 'ST' then  'UNKNOWN'
+ when 'AS' then  'UNKNOWN'
+ else null end as new_status,
+  
+ *  from a where FloorStatus is null and  disposition is not null
+  
+  
+ )  as table1
+   where new_status is null")
 [1] dummy_disposition new_status        Ueid              Date              EndDate          
 [6] Site              CFD               Type              ScheduleId        EventType        
[11] FloorStatus       EntityCode        Ceid              Process           Supplier         
[16] FA                MfgType           Disposition       Comments          extra1           
[21] extra2            extra3           
<0 rows> (or 0-length row.names)

但是当我在查询下面运行时它不会运行:(这很有趣,因为除了更新表部分之外,其余查询是上述查询的一部分。

> sqldf("update a set FloorStatus = case Disposition
+ when 'Disposition' then  'UNKNOWN'
+ when 'Donate' then  'EOL'
+ when 'Resale' then  'EOL'
+ when 'Harvest' then  'EOL'
+ when 'IntelSpinOff' then  'EOL'
+ when 'Scrap' then  'EOL'
+ when 'BufferFeedForward' then   'ACTIVE'
+ when 'FB' then  'UNKNOWN'
+ when 'Unknown' then  'UNKNOWN'
+ when 'HarvestResale' then  'EOL'
+ when 'ReturnToSupplier' then  'EOL'
+ when 'IcapResale' then  'EOL'
+ when 'NonEmsManaged' then  'EOL'
+ when 'BufferEOL' then  'EOL'
+ when 'ResaleScrap' then  'EOL'
+ when 'ST' then  'UNKNOWN'
+ when 'AS' then  'UNKNOWN'
+ else null end
+    from a where FloorStatus is null and  disposition is not null")
Error in sqliteExecStatement(con, statement, bind.data) : 
  RS-DBI driver: (error in statement: near "from": syntax error)

我的更新表命令有什么问题?当我在 sql development studio 中运行我的代码时,它运行良好……但如果代码在 R 中运行,我更喜欢

更新:

我需要对以下代码进行哪些更改????

declare @outputs table 
([day] datetime,
floorstatus varchar,  
 quantity int)

declare @Date datetime;


DECLARE dates_cursor CURSOR FOR
SELECT clndr_dt from epsd.dbo.t_calendar
              where clndr_dt between '2008-01-01' and '2013-08-13'
              order by clndr_dt
OPEN dates_cursor
FETCH NEXT from dates_cursor INTO @Date

WHILE @@FETCH_STATUS = 0
    BEGIN

insert @outputs
       select @Date as [Day], floorstatus, count(floorstatus) as quantity from Graph_data
       where @Date between [Date] and EndDate
       group by floorstatus

FETCH NEXT from dates_cursor INTO @Date
END
CLOSE dates_cursor
DEALLOCATE dates_cursor

select * from @outputs
4

1 回答 1

2

Update 没有from子句(请参阅SQLite 站点上的更新语法),另请参阅sqldf FAQ #8,了解在 SQLite 中更新表但未将表返回到 R 的常见错误。

于 2013-08-19T09:21:09.840 回答