我将一些数据从csv文件导出到R.我使用sqldf包来udpate数据。我的下面的查询运行。我可以提供我的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开发工作室中运行我的代码时运行正常...但我更喜欢代码在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
答案 0 :(得分:2)
更新没有from
子句(请参阅update syntax on SQLite site),另请参阅sqldf FAQ #8,了解更新SQLite中表的常见错误,但未将表返回给R.