Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Display streak

$
0
0

Hi everyone,

Env : SQL Serveur 2008 R2

I want to build a standing with the "actual streak" (Winning or losing) for each team. I have created a small table with random results in it. Really similar to many sports standing.

In the table resultID : 1 = Win and 2 = Lost

CREATE TABLE [dbo].[teamResult](
	[TeamID] [int] NULL,
	[SeasonID] [int] NULL,
	[ResultID] [int] NULL,
	[dateGame] [date] NULL
) ON [PRIMARY]

GO
INSERT [dbo].[teamResult] ([TeamID], [SeasonID], [ResultID], [dateGame]) VALUES (1, 1, 1, CAST(0x01380B00 AS Date))
GO
INSERT [dbo].[teamResult] ([TeamID], [SeasonID], [ResultID], [dateGame]) VALUES (1, 1, 1, CAST(0x02380B00 AS Date))
GO
INSERT [dbo].[teamResult] ([TeamID], [SeasonID], [ResultID], [dateGame]) VALUES (1, 1, 2, CAST(0x03380B00 AS Date))
GO
INSERT [dbo].[teamResult] ([TeamID], [SeasonID], [ResultID], [dateGame]) VALUES (1, 1, 1, CAST(0x04380B00 AS Date))
GO
INSERT [dbo].[teamResult] ([TeamID], [SeasonID], [ResultID], [dateGame]) VALUES (1, 1, 2, CAST(0x05380B00 AS Date))
GO
INSERT [dbo].[teamResult] ([TeamID], [SeasonID], [ResultID], [dateGame]) VALUES (1, 1, 2, CAST(0x06380B00 AS Date))
GO
INSERT [dbo].[teamResult] ([TeamID], [SeasonID], [ResultID], [dateGame]) VALUES (1, 2, 2, CAST(0x07380B00 AS Date))
GO
INSERT [dbo].[teamResult] ([TeamID], [SeasonID], [ResultID], [dateGame]) VALUES (2, 1, 2, CAST(0x01380B00 AS Date))
GO
INSERT [dbo].[teamResult] ([TeamID], [SeasonID], [ResultID], [dateGame]) VALUES (2, 1, 2, CAST(0x02380B00 AS Date))
GO
INSERT [dbo].[teamResult] ([TeamID], [SeasonID], [ResultID], [dateGame]) VALUES (2, 1, 1, CAST(0x03380B00 AS Date))
GO
INSERT [dbo].[teamResult] ([TeamID], [SeasonID], [ResultID], [dateGame]) VALUES (3, 2, 1, CAST(0x14380B00 AS Date))
GO
INSERT [dbo].[teamResult] ([TeamID], [SeasonID], [ResultID], [dateGame]) VALUES (3, 2, 1, CAST(0x15380B00 AS Date))
GO
INSERT [dbo].[teamResult] ([TeamID], [SeasonID], [ResultID], [dateGame]) VALUES (3, 2, 1, CAST(0x16380B00 AS Date))
GO
INSERT [dbo].[teamResult] ([TeamID], [SeasonID], [ResultID], [dateGame]) VALUES (3, 2, 1, CAST(0x17380B00 AS Date))
GO
INSERT [dbo].[teamResult] ([TeamID], [SeasonID], [ResultID], [dateGame]) VALUES (4, 2, 2, CAST(0x14380B00 AS Date))
GO
INSERT [dbo].[teamResult] ([TeamID], [SeasonID], [ResultID], [dateGame]) VALUES (4, 2, 2, CAST(0x15380B00 AS Date))
GO
INSERT [dbo].[teamResult] ([TeamID], [SeasonID], [ResultID], [dateGame]) VALUES (4, 2, 2, CAST(0x16380B00 AS Date))
GO
INSERT [dbo].[teamResult] ([TeamID], [SeasonID], [ResultID], [dateGame]) VALUES (4, 2, 2, CAST(0x17380B00 AS Date))
GO

I hope that someone can help me. 

Thanks and have a great day !

Richard

(Oh, and before someone ask, no it's not for a school project ... I'm done with school since a Looooong time ... it's for a personnal use and to learn more on SQL and complex scenario)


Richard Martin Web Developer / BI Developer


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>