In my work, I always extract from sql, tables, in one of these tables the extracted information is contracts, date, dial qtde, attendee qtde, alo qtde, and so on. I emphasize that I use Rstudio, with a connection via odbc to extract the base. The question is how do I include a column in that select ai, and I need a column of phones. Esssa is the code
sql_server_temp <- sqlQuery(channel = conn, query =
paste0("SELECT x.Contrato, x.data_registro, x.cart, SUM(x.Discado) AS disc_esf, SUM(x.Atendido) AS atend_esf, SUM(x.alo) AS alo_esf, SUM(x.cpc) AS cpc_esf, ",
"SUM(x.Discado_unique) AS disc_uni, SUM(x.Atendido_unique) AS atend_uni, SUM(x.alo_unique) AS alo_uni, SUM(x.cpc_unique) AS cpc_uni ",
"FROM (SELECT Data_Registro, 'ADM' AS cart, CAST(Contrato AS VARCHAR(100)) AS Contrato,SUM(CASE WHEN Discado = 'S' THEN 1 ELSE 0 END) AS Discado, ",
"SUM(CASE WHEN Atendido = 'S' THEN 1 ELSE 0 END) AS Atendido, SUM(CASE WHEN alo = 'S' THEN 1 ELSE 0 END) AS alo, ",
"SUM(CASE WHEN cpc = 'S' THEN 1 ELSE 0 END) AS cpc, CASE WHEN SUM(CASE WHEN Discado = 'S' THEN 1 ELSE 0 END)>0 THEN 1 ELSE 0 END AS Discado_unique, ",
"CASE WHEN SUM(CASE WHEN Atendido = 'S' THEN 1 ELSE 0 END)>0 THEN 1 ELSE 0 END AS Atendido_unique, CASE WHEN SUM(CASE WHEN alo = 'S' THEN 1 ELSE 0 END)>0 THEN 1 ELSE 0 END AS alo_unique, ",
"CASE WHEN SUM(CASE WHEN cpc = 'S' THEN 1 ELSE 0 END)>0 THEN 1 ELSE 0 END AS cpc_unique FROM Vw_Acionamento ",
"WHERE tipo_discagem = 'OUTBOUND' AND Cod_Carteira IN (98) AND Data_Registro BETWEEN '",data_ini,"' AND '",data_fini,"' ",
"GROUP BY Data_Registro, CAST(Contrato AS VARCHAR(100))) AS x GROUP BY x.Contrato,x.Data_Registro, x.cart"))
As already mentioned, there is the possibility of including a column there, help me.