2
下面的代碼打印:R中鮮明而使用DBI包連接到PostgreSQL
SELECT "district_code" FROM sd_stage.table1 GROUP BY "district_code"
,但我期待:
select distinct(district_code) from sd_stage.table1
代碼:
library(DBI)
library(tidyverse)
library(dbplyr)
conn_obj <- DBI::dbConnect(RPostgreSQL::PostgreSQL(),
host = "127.0.0.1",
user = "testingdb",
password = "[email protected]")
on.exit(DBI::dbDisconnect(conn_obj))
tbl_oil_root_segment <- dplyr::tbl(conn_obj,
dbplyr::in_schema('sd_stage','table1'))
tbl_oil_root_segment %>% distinct(oil_district) %>% show_query()
輸出是正確的,但生成的查詢似乎不是100%。那麼無論如何,我可以實現查詢?
我怎麼能在上面的代碼中使用ORDER_BY你提到的這麼oil_district是有序... – Sharath
你可以用'從dplyr arrange'。 – Scarabee