0
Considering the table:
CREATE TABLE [dbo].[VENDAS](
[VENCIMENTO] [datetime] NULL,
[VENCIDO] [decimal](18, 0) NULL,
[RECEBIDO] [decimal](18, 0) NULL
) ON [PRIMARY]
INSERT INTO VENDAS VALUES('2019-01-10', 50, 49,80)
INSERT INTO VENDAS VALUES('2019-02-10', 50, 49.80)
INSERT INTO VENDAS VALUES('2019-03-10', 50, 49,80)
How to achieve this result:
I tried to come up with a result but to no avail. I used this consultation:
SELECT *
FROM (SELECT VENCIDO, RECEBIDO, VENCIMENTO
FROM VENDAS) AS V
PIVOT (SUM(V.RECEBIDO) FOR V.RECEBIDO IN ([0])) AS PV1
In case the Maturity records turn into columns.
This is not pivot but matrix transposition. A solution is to mount 3 SELECT, one for each line of the result, and reunite them with UNION ALL.
– José Diz
Suggested reading: https://gustavomaiaaguiar.wordpress.com/2009/07/13/pivoteando-despivoteando-transpondo-invertendo-colunas-e-linhas-no-sql-server/
– José Diz