Python sql中应为不匹配的输入“as”

Python sql中应为不匹配的输入“as”,python,sql,Python,Sql,我的问题如下 for i in range(0,100000,10000): query= """select distinct icustay_id, date_diff('second', timestamp '1970-01-01 00:00:00', charttime) as charttime, itemid, case when value = 'None' then '0' when value = 'Ventilator' then '1' whe

我的问题如下

for i in range(0,100000,10000):

    query= """select distinct icustay_id, date_diff('second', timestamp '1970-01-01 
    00:00:00', charttime) as charttime, itemid, case when value = 'None' then '0' when value 
    = 'Ventilator' then '1' when value='Cannula' then '2' when value = 'Nasal Cannula' then 
   '2' when value = 'Face Tent' then '3' when value = 'Aerosol-Cool' then '4' when value = 
   'Trach Mask' then '5' when value = 'Hi Flow Neb' then '6' when value = 'Non-Rebreather' 
   then '7' when value = '' then '8'  when value = 'Venti Mask' then '9' when value = 
   'Medium Conc Mask' then '10' else 'valuenum end' as 'valuenum' 

   from mimiciii.chartevents 

   where icustay_id>="+str(200000+i)+" and icustay_id< " + str(210000+i) + " and value is 
   not null and itemid in (467,470,471,223834,227287,194,224691,226707,226730,581,580,224639,226512,198,228096,211,220045   ,220179,225309,6701,6,227243,224167,51,455, 220181,220052,225312,224322,6702,443,52,456,8368,8441,225310,8555,8440,220210,3337,224422,618,3603,615,220277,646,834,3655,223762,223761,678,220074,113,492,491,8448,116,1372,1366,228368,228177,626,223835,3420,160,727,190,220339,506,505,224700,224686,224684,684,224421,224687,450,448,445,224697,444,224695,535,224696,543,3083,2566,654,3050,681,2311)  order by icustay_id, charttime "
我犯了这样的错误

调用StartQueryExecution操作时发生InvalidRequestException错误:第1:556行:不匹配的输入“应为“{.”、“[”、“AT”、“OR”、“AND”、“IN”、“NOT”、“BETWEEN”、“LIKE”、“IS”、“END”、“END”、“NEQ”、“=”、“+”、“-”、“*”、“/”、“%”、“%”、“| 无法回滚


在我看来,可能有一个简单的修复方法,比如某个地方缺少了一些东西。

根据评论,我将其他'valuenum end'更改为'valuenum'end,并成功。

尝试从中删除'valuenum end'作为'valuenum'检查此方法是否有效:'valuenum end'valuenum'删除'valuenum end'后仍然存在相同的错误应该是'valuenum'结尾