转换变量更改变量名称 - SQL
Cast variable changes variable name - SQL
我是 SQL 的新手,当我尝试将变量转换为文本而不是数字时,我很困惑为什么变量名称会发生变化。
我正在使用 RSQLite,我想从我的 dbi 连接中提取一些列并将一些变量转换为文本类型。
这是我的代码:
head5_query <- dbSendQuery(con,"SELECT studyid,
candidategroup,
submissionmonth,
submissionyear,
CAST(membercounty AS TEXT),
CAST(serviceprovidercounty AS TEXT),
CAST(admissionsource AS TEXT)
FROM medicalClaims WHERE studyid IS NOT NULL AND dateofservicetomonth = 1 AND dateofservicetoyear = 2011 LIMIT 5")
head_query = dbFetch(head5_query,n = -1)
head_query
这给了我:
> head_query
studyid candidategroup submissionmonth submissionyear CAST(membercounty AS TEXT) CAST(serviceprovidercounty AS TEXT)
1 145311.10 1 2 2014 Bristol Suffolk
2 36458.10 1 5 2014 Suffolk Suffolk
3 12403.17 1 2 2014 <NA> Suffolk
4 12403.16 1 2 2014 <NA> Suffolk
5 12403.15 1 2 2014 <NA> Suffolk
CAST(admissionsource AS TEXT) medicalclaimid apcdidcode
1 <NA> 22778326 4
2 2.0 46829274 0
3 1.0 64643334 0
4 1.0 64643334 0
5 1.0 64643334 0
其中变量名称已更改为 CAST(membercounty AS TEXT),例如。但是,变量类型似乎已更改为文本:
> class(head_query$`CAST(admissionsource AS TEXT)`)
[1] "character"
如何在不更改变量名称的情况下更改变量类型?
非常感谢!
在使用函数修改它们时,您需要 ALIAS
您的列(它们不是 SELECT
语句中的变量)。
https://www.tutorialspoint.com/sqlite/sqlite_alias_syntax.htm
我是 SQL 的新手,当我尝试将变量转换为文本而不是数字时,我很困惑为什么变量名称会发生变化。
我正在使用 RSQLite,我想从我的 dbi 连接中提取一些列并将一些变量转换为文本类型。
这是我的代码:
head5_query <- dbSendQuery(con,"SELECT studyid,
candidategroup,
submissionmonth,
submissionyear,
CAST(membercounty AS TEXT),
CAST(serviceprovidercounty AS TEXT),
CAST(admissionsource AS TEXT)
FROM medicalClaims WHERE studyid IS NOT NULL AND dateofservicetomonth = 1 AND dateofservicetoyear = 2011 LIMIT 5")
head_query = dbFetch(head5_query,n = -1)
head_query
这给了我:
> head_query
studyid candidategroup submissionmonth submissionyear CAST(membercounty AS TEXT) CAST(serviceprovidercounty AS TEXT)
1 145311.10 1 2 2014 Bristol Suffolk
2 36458.10 1 5 2014 Suffolk Suffolk
3 12403.17 1 2 2014 <NA> Suffolk
4 12403.16 1 2 2014 <NA> Suffolk
5 12403.15 1 2 2014 <NA> Suffolk
CAST(admissionsource AS TEXT) medicalclaimid apcdidcode
1 <NA> 22778326 4
2 2.0 46829274 0
3 1.0 64643334 0
4 1.0 64643334 0
5 1.0 64643334 0
其中变量名称已更改为 CAST(membercounty AS TEXT),例如。但是,变量类型似乎已更改为文本:
> class(head_query$`CAST(admissionsource AS TEXT)`)
[1] "character"
如何在不更改变量名称的情况下更改变量类型?
非常感谢!
在使用函数修改它们时,您需要 ALIAS
您的列(它们不是 SELECT
语句中的变量)。
https://www.tutorialspoint.com/sqlite/sqlite_alias_syntax.htm