SQL query with WITH to group

Asked

Viewed 29 times

0

what should change in my consultation

WITH Consulta AS
  (SELECT DT_RFRN_MVMN,
    TX_DATA_VNDA,
    CD_BNDR,
    CD_CRDE,
    CD_PCSR CD_EMSR,
    CD_TIPO_PLTF_PGMN,
    CD_TIPO_TRNS_BNDR_RECB,
    CD_TIPO_APRS_TRNS_RECB,
    CD_PRDT_BNDR_RECB,
    numerolinha= row_number() over (partition BY CD_PRDT_BNDR_RECB order by CD_CRDE DESC)
  FROM CLC.TBCLCR_LNCM_RECB
  )
SELECT DT_RFRN_MVMN,
  TX_DATA_VNDA,
  CD_BNDR,
  CD_CRDE,
  CD_PCSR CD_EMSR,
  CD_TIPO_PLTF_PGMN,
  CD_TIPO_TRNS_BNDR_RECB,
  CD_TIPO_APRS_TRNS_RECB,
  CD_PRDT_BNDR_RECB
FROM Consulta
WHERE numerolinha = 1; 

To bring the result grouped by CD_PRDT_BNDR_RECB

1 answer

0

WITH Consulta AS
  (SELECT DT_RFRN_MVMN,
    TX_DATA_VNDA,
    CD_BNDR,
    CD_CRDE,
    CD_PCSR CD_EMSR,
    CD_TIPO_PLTF_PGMN,
    CD_TIPO_TRNS_BNDR_RECB,
    CD_TIPO_APRS_TRNS_RECB,
    CD_PRDT_BNDR_RECB,
    numerolinha= row_number() over (partition BY CD_PRDT_BNDR_RECB order by CD_CRDE DESC)
  FROM CLC.TBCLCR_LNCM_RECB
  )
SELECT DT_RFRN_MVMN,
  TX_DATA_VNDA,
  CD_BNDR,
  CD_CRDE,
  CD_PCSR CD_EMSR,
  CD_TIPO_PLTF_PGMN,
  CD_TIPO_TRNS_BNDR_RECB,
  CD_TIPO_APRS_TRNS_RECB,
  CD_PRDT_BNDR_RECB
FROM Consulta
WHERE numerolinha = 1
GROUP BY CD_PRDT_BNDR_RECB;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.