4
I have the FAULTS table with the following columns:
CREATE TABLE [dbo].[FALTAS](
[Id] [int] IDENTITY(1,1) NOT NULL,
[Matricula] [int] NOT NULL,
[Dia] [date] NOT NULL,
[Situacao] [varchar](50) NOT NULL,
CONSTRAINT [PK_FALTAS] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
Dice:
INSERT INTO FALTAS (Matricula,Dia,Situacao) VALUES(31,'2014-06-11','FALTA');
INSERT INTO FALTAS (Matricula,Dia,Situacao) VALUES(31,'2014-06-13','PRESENTE');
INSERT INTO FALTAS (Matricula,Dia,Situacao) VALUES(31,'2014-06-12','FALTA');
INSERT INTO FALTAS (Matricula,Dia,Situacao) VALUES(140,'2014-06-12','PRESENTE');
INSERT INTO FALTAS (Matricula,Dia,Situacao) VALUES(140,'2014-06-11','PRESENTE');
INSERT INTO FALTAS (Matricula,Dia,Situacao) VALUES(140,'2014-06-13','CURSO');
INSERT INTO FALTAS (Matricula,Dia,Situacao) VALUES(200,'2014-06-11','CURSO');
INSERT INTO FALTAS (Matricula,Dia,Situacao) VALUES(200,'2014-06-12','FALTA');
INSERT INTO FALTAS (Matricula,Dia,Situacao) VALUES(200,'2014-06-13','PRESENTE');
INSERT INTO FALTAS (Matricula,Dia,Situacao) VALUES(217,'2014-06-12','PRESENTE');
INSERT INTO FALTAS (Matricula,Dia,Situacao) VALUES(217,'2014-06-13','FALTA');
INSERT INTO FALTAS (Matricula,Dia,Situacao) VALUES(217,'2014-06-11','FALTA');
INSERT INTO FALTAS (Matricula,Dia,Situacao) VALUES(223,'2014-06-11','PRESENTE');
INSERT INTO FALTAS (Matricula,Dia,Situacao) VALUES(223,'2014-06-12','FALTA');
INSERT INTO FALTAS (Matricula,Dia,Situacao) VALUES(223,'2014-06-13','PRESENTE');
and I need to show you how:
Matricula 11/06/2014 12/06/2014 13/06/2014
31 FALTA FALTA PRESENTE
140 PRESENTE PRESENTE CURSO
200 CURSO FALTA PRESENTE
217 FALTA PRESENTE FALTA
223 PRESENTE FALTA PRESENTE
I know that the PIVOT operator changes the position of the row information to the column, but I could not find any example without the use of aggregator(SUM,COUNT,etc)
An exit in this case is to use a MAX, "take a turn" as it is a function of aggregation.
– Motta
http://stackoverflow.com/questions/24470/sql-server-pivot-examples
– Motta
@Motta, the examples you sent me helped me, but I’m going to have to set up a dynamic consultation.
– lll_JR_lll