Jump to content
Fórum Script Brasil
  • 0

(Resolvido) Transformar colunas em Linhas


Question

5 answers to this question

Recommended Posts

  • 0
  • 0

Tenta assim

SELECT
    'Faturado' DESCR,
    (SELECT SUM(faturado) FROM `table` WHERE `mes` = 1 AND `ano` = 2019) 1,
    (SELECT SUM(faturado) FROM `table` WHERE `mes` = 2 AND `ano` = 2019) 2,
    (SELECT SUM(faturado) FROM `table` WHERE `mes` = 3 AND `ano` = 2019) 3
UNION ALL
SELECT
    'Vendido' DESCR,
    (SELECT SUM(vendido) FROM `table` WHERE `mes` = 1 AND `ano` = 2019) 1,
    (SELECT SUM(vendido) FROM `table` WHERE `mes` = 2 AND `ano` = 2019) 2,
    (SELECT SUM(vendido) FROM `table` WHERE `mes` = 3 AND `ano` = 2019) 3
UNION ALL
SELECT
    'Despesas' DESCR,
    (SELECT SUM(despesas) FROM `table` WHERE `mes` = 1 AND `ano` = 2019) 1,
    (SELECT SUM(despesas) FROM `table` WHERE `mes` = 2 AND `ano` = 2019) 2,
    (SELECT SUM(despesas) FROM `table` WHERE `mes` = 3 AND `ano` = 2019) 3
Link to post
Share on other sites
  • 0
1 hora atrás, Leonardo Persan disse:

Tenta assim

SELECT
    'Faturado' DESCR,
    (SELECT SUM(faturado) FROM `table` WHERE `mes` = 1 AND `ano` = 2019) 1,
    (SELECT SUM(faturado) FROM `table` WHERE `mes` = 2 AND `ano` = 2019) 2,
    (SELECT SUM(faturado) FROM `table` WHERE `mes` = 3 AND `ano` = 2019) 3
UNION ALL
SELECT
    'Vendido' DESCR,
    (SELECT SUM(vendido) FROM `table` WHERE `mes` = 1 AND `ano` = 2019) 1,
    (SELECT SUM(vendido) FROM `table` WHERE `mes` = 2 AND `ano` = 2019) 2,
    (SELECT SUM(vendido) FROM `table` WHERE `mes` = 3 AND `ano` = 2019) 3
UNION ALL
SELECT
    'Despesas' DESCR,
    (SELECT SUM(despesas) FROM `table` WHERE `mes` = 1 AND `ano` = 2019) 1,
    (SELECT SUM(despesas) FROM `table` WHERE `mes` = 2 AND `ano` = 2019) 2,
    (SELECT SUM(despesas) FROM `table` WHERE `mes` = 3 AND `ano` = 2019) 3

Obrigado, assim deu certo

Link to post
Share on other sites
Guest
This topic is now closed to further replies.


  • Forum Statistics

    • Total Topics
      148692
    • Total Posts
      644524
×
×
  • Create New...