如标题所示,我想连接 SQL Server 中表中的几列,我尝试使用 paste
函数,如下所示,但出现以下错误:
> tbl(channel,'##iris') %>%
+ mutate(string=paste(Species,'-',
+ Sepal.Length,'-',
+ Sepal.Width,'-',
+ Petal.Length,'-',
+ Petal.Width,sep=''))
Error: PASTE() is not available in this SQL variant
最佳答案
我找到了解决方案here由 Ben Baumer 提供,并希望在此分享。
方法是使用CONCAT
而不是paste
。
> tbl(channel,'##iris') %>%
+ group_by(Species,Sepal.Length,Sepal.Width,Petal.Length,Petal.Width) %>%
+ summarise(string=MAX(CONCAT(Species,'-',
+ Sepal.Length,'-',
+ Sepal.Width,'-',
+ Petal.Length,'-',
+ Petal.Width))) %>%
+ head(.,1)
# Source: lazy query [?? x 6]
# Database: Microsoft SQL Server 11.00.6251[dbo@WCDCHCMSAH01\CMSAH_DC7_MP1/data_ha_amr]
# Groups: Species, Sepal.Length, Sepal.Width, Petal.Length
Species Sepal.Length Sepal.Width Petal.Length Petal.Width string
<chr> <dbl> <dbl> <dbl> <dbl> <chr>
1 setosa 4.30 3.00 1.10 0.100 setosa-4.3-3-1.1-0.1
关于sql-server - 如何使用 dplyr 连接 SQL Server 中表中多列的字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48536983/