SQL query with WITH to group

0

What should change in my query

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

    
asked by anonymous 07.11.2017 / 19:51

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;
    
07.11.2017 / 22:09