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)

update table コマンドの何が問題になっていますか? コードを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
4

1 に答える 1