Return of several CASE in a single line

Asked

Viewed 79 times

-1

How do I convert that return: inserir a descrição da imagem aqui

In a single line:

548721  125 2   20836   20836   77821   77821   9999******9999  0   0   MASTERCARD  200 Cartao de Credito a Vista

My query:

SELECT
    CASE data_id WHEN 17  THEN data_value ELSE 0 END AS bin_cartao,
    CASE data_id WHEN 18  THEN data_value ELSE 0 END AS rede,
  CASE data_id WHEN 96  THEN data_value ELSE 0 END AS bandeira,
  CASE data_id WHEN 203 THEN data_value ELSE 0 END AS nsu_sitef,
  CASE data_id WHEN 204 THEN data_value ELSE 0 END AS nsu_host,
  CASE data_id WHEN 205 THEN data_value ELSE 0 END AS nsu_credito,
    CASE data_id WHEN 160 THEN data_value ELSE 0 END AS autorizacao,
  CASE data_id WHEN 16  THEN data_value ELSE 0 END AS aprovacao,
  CASE data_id WHEN 16  THEN data_value ELSE 0 END AS aprovacao_adm,
  CASE data_id WHEN 104 THEN data_value ELSE 0 END AS cartao,
  CASE data_id WHEN 240 THEN data_value ELSE 0 END AS descricao,
  CASE data_id WHEN 294 THEN data_value ELSE 0 END AS cod_modalidade,
  CASE data_id WHEN 295 THEN data_value ELSE 0 END AS desc_modalidade
FROM
    sale_media_data
WHERE
    store_key = 2
AND pos_number = 52
AND ticket_number = 734701
AND DATE(start_time) = '2020-03-02';

1 answer

0

SELECT
  max(result.bin_cartao),
  max(result.rede),
  max(result.bandeira),
  max(result.nsu_sitef),
  max(result.nsu_host),
  max(result.nsu_credito),
  max(result.autorizacao),
  max(result.aprovacao),
  max(result.aprovacao_adm),
  max(result.cartao),
  max(result.descricao),
  max(result.cod_modalidade),
  max(result.desc_modalidade)
FROM
(SELECT
  CASE data_id WHEN 17  THEN data_value ELSE 0 END AS bin_cartao,
  CASE data_id WHEN 18  THEN data_value ELSE 0 END AS rede,
  CASE data_id WHEN 96  THEN data_value ELSE 0 END AS bandeira,
  CASE data_id WHEN 203 THEN data_value ELSE 0 END AS nsu_sitef,
  CASE data_id WHEN 204 THEN data_value ELSE 0 END AS nsu_host,
  CASE data_id WHEN 205 THEN data_value ELSE 0 END AS nsu_credito,
    CASE data_id WHEN 160 THEN data_value ELSE 0 END AS autorizacao,
  CASE data_id WHEN 16  THEN data_value ELSE 0 END AS aprovacao,
  CASE data_id WHEN 16  THEN data_value ELSE 0 END AS aprovacao_adm,
  CASE data_id WHEN 104 THEN data_value ELSE 0 END AS cartao,
  CASE data_id WHEN 240 THEN data_value ELSE 0 END AS descricao,
  CASE data_id WHEN 294 THEN data_value ELSE 0 END AS cod_modalidade,
  CASE data_id WHEN 295 THEN data_value ELSE 0 END AS desc_modalidade
FROM
    sale_media_data
WHERE
    store_key = 2
AND pos_number = 52
AND ticket_number = 734701
AND DATE(start_time) = '2020-03-02'
) as result ;

Or Something Similar, as the values other than 0 are considered May, then only the values greater than each line will be returned.

Browser other questions tagged

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