Display streak

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

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
;with mycte as
(Select *,row_number() Over(Partition by SeasonID,TeamID Order by dateGame) rn
,row_number() Over(Partition by SeasonID,TeamID,ResultID Order by dateGame) rn2,
row_number() Over(Partition by SeasonID,TeamID Order by dateGame)-
row_number() Over(Partition by SeasonID,TeamID,ResultID Order by dateGame) rn3
from [dbo].[teamResult]
,mycte1 as (
Select SeasonID,TeamID,ResultID,dateGame, rn, rn3, Case WHEN ResultID=1 Then 1 Else -1 END as PositiveOrNegative
from mycte)
Select a.SeasonID,a.TeamID,a.ResultID,a.dateGame,Sum(b.PositiveOrNegative) as [actualstreak]
from mycte1 a
left join mycte1 b on
a.SeasonID=b.SeasonID
AND a.TeamID=b.TeamID
AND a.ResultID=b.ResultID
AND a.rn3=b.rn3 AND a.rn>=b.rn
Group by a.SeasonID,a.TeamID,a.ResultID,a.dateGame
Order by SeasonID,TeamID,dateGame
drop table [dbo].[teamResult]

Similar Messages

  • 2012 13" display streaks

    Is anyone else experiencing what appear to be white-ish streaks on their 13 inch panels? Pretty sure its a backlighting issue, and its really only noticable during times where the display is projecting a primarily darker image. Primarily in the lower left corner of the display  Gonna take it in to be replaced but wondering if this is a known issue with the displays.

    ask if its a known issue when you take it in.

  • Computer stuck during normal operation with weird display

    My Toshiba Satellite M205-S4806 is getting stuck pretty quickly after startup.
    The display displays streaks as shown in the attached picture.
    This does not happen in safe mode.
    I thought that reinstalling the OS would solve the problem, but during installation of Windows 8 it happens again.
    I ran out of ideas as for the cause of the problem or it's solution.
    Attachments:
    DSC_0497.JPG ‏1021 KB

    Hi ! If Dave's suggestion doesn't work, you might try a clean boot.http://support.microsoft.com/kb/929135
    I Love my Satellite L775D-S7222 Laptop. Some days you're the windshield, Some days you're the bug. The Computer world is crazy. If you have answers to computer problems, pass them forward.

  • 15" G4 powerbook display fault

    My 2005 powerbook has developed a critical display problem. Like several I have seen on youtube. The display streaks across the screen. Mouse movements move pixels around. A knock above the optical drive solved it briefly but now that knock generally results in instant shutdown and the power button does nothing. When you close the lid it switches on again but comes up on the mac-boot page. Moving the screen does nothing. any ideas welcome. Anticipating a huge repair bill 4 years out of warrenty. Paid £1600 for this so am reluctant to part with it so soon.
    Bo

    Where do you tap it is it around where the ram door is? The most effective test to perform now is plug it into an external monitor and see if the problem on the screen also appears on the external display. If it does, this is quite serious because it means the graphics card has had it. The other thing you can do is to go to this website and download iStat Nano.
    http://www.apple.com/downloads/dashboard/status/istatnano.html
    It is a simple dashboard widget that tells you basic info about your mac. Such as battery life, hard drive and memory being used up and so forth. The feature we are interested in here however is the temperature sensors in the PowerBook that report to iStat. We can see how hot the GPU/CPU or hard drive is with this app. You can conduct a little test with this app. Measure the temperature when you start the mac up and measure it again when the issue occurs. This way we can determine if the issue is heat related. You can also use the help of the fan speed to isolate whether the issue is due to temperature or not. You should find the left fan run faster as the machine heats up as this controls the cooling of the GPU.
    Report back to me with your results and we can go on from there.

  • Bug graphique(CC 2014.2)

    Bonjour..Problème  sous CC 2014.2, calques 3D aléatoire,bug affichages,stries de pixels,artefacts! j'ai réinstallé,paramétrer mais rien ni fait je doute que cela vienne de ma configue( 3,5 GHz Intel Core i7-NVIDIA GeForce GTX 780M 4096 Mo)
    Quelqu'un a t-il eu ce genre de problème? je précise que tous ces bug d'affichages surviennent uniquement en utilisation 3D.
    A l'aide!

    Hello..Problem under CC 2014.2, random 3D layers, bug displays, streaks of pixels, artifacts! I reinstalled, set up but nothing and madeI doubt that this comes from ma configue (3.5 GHz Intel Core i7-NVIDIA GeForce GTX 780 M 4096 MB)
    Anyone has t - had this kind of problem? I should mention that all these views bug occur only in use 3D.
    The help!
    Is the GPU driver up to date?
    Does the problem persist when rendering?
    http://blogs.adobe.com/crawlspace/2012/07/photoshop-basic-troubleshooting-steps-to-fix-mos t-issues.html

  • Streak on display

    Bought the HD Cinema display under 2 years ago, it is my primary display and sits beside a 15 year old Taxan 15" cheap plastic trimmed secondary screen.
    Whilst the Taxan has worked flawlessly over the years, l see that my Apple HD Cinema screen contains an ever extending streak behind the glass. It looks like the sort of stain you would see on a water damaged book.
    The screen has remained in the same location since purchase, has only ever been lightly cleaned with a duster and definitely never been any fluids/liquids.
    Has anyone else had the same issue?

    I have the same problem. Only appeared this week. Did apple have an answer to why it would happen?

  • Using a IP191 monitor, have random horizontal streaks on display - have no problem with other browsers; also no problem with FF on other family PC's

    Using a IP191 monitor, have random horizontal streaks on display - have no problem with other browsers; also no problem with FF on other family PC's.
    These "streaks" appear to be area of too high frequency scanning; they can be cleared by scrolling up and/or down.

    hello, maybe that's an issue with hardware acceleration - please try [[Upgrade your graphics drivers to use hardware acceleration and WebGL|updating your graphics driver]], or in case this doesn't solve the issue or there is no new version available at the moment, disable hardware acceleration in the firefox ''menu [[Image:New Fx Menu]] > options > advanced > general''.

  • Brand new iMac 24" 2.4 streaked dirty display

    Hello: I apologize if this question has been previously asked, it appears that there are many display issues with these new iMacs...
    I purchased an iMac 2.4/320GB HD/1GB RAM/256MB VRAM from the MacConnection on October 15, 2008. I've been having some issues with the display and was wondering if I could get any input.
    The first problem I noticed when the machine was first powered up, there appears to be a speck of dust that is reflecting off of the glass panes so it actually looks like 2 specs of dust.
    The second problem is that a fireworks/spider web type pattern has appeared on the left hand side of the screen (which seems to run a lot warmer than the right hand side) that has emerged in the couple of months I've had it.
    Both issues appear to be on the inside of the glass, and earlier today I received instructions from a YouTube video on how to remove the glass with a suction cup. It appears that both of the problems are not on the inside of the outer glass, but they appear to be on the inside of the inner LCD display itself. I've only used the dampened cleaning cloth that came with the machine to clean all of these areas, but the streaks and dust are not going away.
    I work with an Apple certified tech who told me to try a product called I-Kleer but it appears that all of the issues are within the inner screen. I'm aware that there's a year long limited factory warranty that comes with these models, I'm wondering if a problem like this would be covered? I did not purchase an AppleCare plan.
    Any advice? I have a photo of what the screen is doing if needed.

    Hi and thanks for the info. I tried a few things out and resorted to taking it to the Apple store for repair. Good thing I did - they had to replace not only the LCD panel, but the motherboard as well! Didn't have much info but I'm also thinking that a whole batch of them was affected. After a little investigating, it turned out that "spiderweb/fireworks" pattern I was seeing actually turned out to be an outline of my desktop wallpaper photo that was burning into the screen. Took a little while to figure out that was it, but I also started having the same problem some others have had posted in the forums with the screen burn-in. I jumped screens to a site with a dark background, and the eBay logo from the page I was on ten minutes previous jumped up and burned itself in the screen after I closed the window!
    That was quite a major replacement of parts for a brand new machine and I'm thinking of selling it now. My model is a 2.4/320/4/256 with a beginning serial number of W8814. Definitely could be in the same lot as yours.
    Thanks again for your help!

  • Streaks Across iPhone 5S Display

    Hello,
    I have just recently discovered some streaks appearing across my iPhone 5S screen.  It is defiantly display damage,  the streaks are only visible at angles that is not direct onto the screen.  I believe this damage is some water (from condensation) that has slipped under the display but I am uncertain about this.
    What type of damage is this and should I take it into the genius bar?
    Thanks
    http://imgur.com/a/KDFVd

    If you can prove to the Apple Genius that this is dust, ie manufacturing defect, and not a scam image, this will be handled under Apple Warranty.

  • Freezing on start-up, odd display glitches and streaking: what's going on!?

    Hello all,
    Recently the condition of my MacPro's performance has steadily declined and I have no idea what is going on. Upon cold start, the macpro freezes up when the desktop hasn't even properly loaded. Frequently, after having a normal start-up, I see odd graphical stretching and shearing of the display, as if someone were stretching a part of the display like rubber.
    There will also occasionally be odd horizontal streaks (very thin, about a pixel or two wide) running across the screen.
    To add to that, some video has not loaded properly in Safari and has caused frequent application freezes.
    Can anyone pinpoint what is going on with my investment? Is it a graphics card issue, an issue with the HD, an issue of corrupt files/viruses, start-up items, or even dust?
    It seems to be getting worse and its become really annoying.
    I'm not even sure if turning it on is doing it any good anymore.
    Any help on this is greatly appreciated!

    Thanks, sorry I didn't post the specs but I was in a rush. I pulled the side off the tower tonight and I have the ATI Radeon X1900 XT 512MB card in my Mac Pro. It had been running fine since 2007.
    I noticed it had some dust in it so I took everything apart on the tower and cleaned the whole thing. After I put it back together, I do not get the black streaking now. I still get some very small colored specs, but no freezing up of the system either.
    If that card is prone to failure or dust issues = bad performance. Is there an option someone can suggest for the older dual core mac pro's?
    Thanks,
    John M.

  • Pixel streaks on display

    I'm getting pixel streaks all over my two displays (they're both Viewsonics LCD), here are a couple of screenshots:
    http://santiagouceda.com/pixels.jpg
    http://santiagouceda.com/pixels2.jpg
    Has this happened to anyone else, have any idea what the problem is?
    Thanks,
    Santiago
    G5 dual 2.0
    1 gb ram
    G5 Dual 2.0   Mac OS X (10.4.7)  

    Looks just like overclocked GPU / overheated VRAM symptoms, Check to make certain the heatsink on the video card is snug to the GPU with NO PLAY at all. If the VRAM chips on the graphics card are too hot to touch then consider VRAM heatsinks.

  • HORRIBLE green streaks all across my 23" Cinema display

    I have a 23" ACD and it suddenly started showing INSANE green streaks everywhere! I don't know what's wrong with it! It wasn't dropped (that I know of) and doesn't show signs of a cracked screen, but I can't for the life of me figure it out.
    Is it the LCD panel? Inverter? Backlights? DOES ANYONE HAVE ANY IDEA?!? I've attached pictures below. I'm out of warranty and need to find out what to do.
    If I have the LCD display panel replaced with an OEM part, would it correct this problem? Or is it something else internally? If anyone's had this problem, PLEASE HELP and advise!
    when windows is running on parallels - http://img.auctiva.com/imgdata/4/9/8/1/0/9/webimg/358314581_o.jpg
    when the screen isn't entirely filled - http://img.auctiva.com/imgdata/4/9/8/1/0/9/webimg/358314547_o.jpg
    another BAD shot of the display - http://img.auctiva.com/imgdata/4/9/8/1/0/9/webimg/358314609_o.jpg

    Are you sure that it is the monitor and not the video card in your computer?
    Have you tested with another monitor?
    Have you tested the display with another computer?

  • 30 Inch Cinema Display with Vertical Streaks

    Hi All,
    I've started to notice very pale vertical streaks on my screen. So far, they seem to be along the edges and are particularly visible when blues and other dark colors are displayed.
    It's not a big deal, but the monitor was about $2,000 and is only about 2 years old.
    What is this? Is it "normal"?
    I have Apple Care... thinking it might be time to use it!
    Thanks,
    Robert

    Robert, My 30 Apple monitor started with blueish-green vertical lines outlining the texture of my desktop. It is present on photo's, web-pages and even video I may review. Please send me your email and I can send you one of my photo's to see if your problem is the same. I will be meeting with Apple Support tomorrow for help. Sincerely, Joe Ray at: [email protected]

  • IMac 8.1 dual core intel 21.5" 2007/8 has vertical streaks on display screen, what is the cause

    my display has verticle streaks tat seem to be on everything, they are not differently colored than the background, just spaced about every 2.5-3 inches with a light dark light band space of about 2 inches and then again, repeated across the screen. It shows up on everything, but is more visible on some content than others. is it a video card going or what?

    Thanks a lot! If i am going to spend a lot to get it fixed, i think I will wait a while and maybe get a new Imac or maybe a mini mac. with a separate monitor.  I do love my imac, and before we got our macs we had many problems with viruses, crashed hard drives & various other problems. With the Imac, even though my husbands and mine are supposed to be the same they have suttle differences. but I have had a problem with the computer I have on warrenty it needed something replaced, Then this last fall we had 3 power outages in a row. They are on surge protectors, but even so, they shut themselves off, or the power did like a cold boot. after the power came back on, I turned it on, and then shortly thereafter the power went off again. Thensame scenario. and one more power failure. i think it was not the surge as I don;t think there would or could have been one, but because it was basically a cold boot 3 times in a row and the computer did not shut down properly, it crashed and would not come on. My husband, worked on it for a week and finally got a blue screen, and was able to get it going enough to format the hard drive. and re install everything. But a lit of files would not reinstall. I had a small 1 terrabyte backup and it was plugged in and programmed to cycle every day at certain times. Well to make a long story short, it did not like the cold boot any more than the computer. we ere able to save about 1/2 of my files. part of which was my photos. I had had 23,000 photos, and now i had 87,000, unorganized photos with many duplicates. it is a slow proceedure, but I have got that # down to 60,000 so far. I am missing my best folder I had with some genealogy info & other stuff in it. Was my personal folder. It would not load into the re done computer. but I still have the hard drive in case things change. I still love mac & don't think I would go back to PC Sorry to talk your ear off, and thanks again for your help.... Myrna Thordarson

  • Vertical streaks on Lumia 820 display

    I see very distinguishable vertical banding and streaks on my Lumia 820. I first noticed them on dark grey backgrounds but now also on e.g. Nokia TV menus. Is this normal?

    no this is not normal at all. have you tried performing a soft reset (pressing the volume down and power buttons together until the phone vibrates)? Failing that, it sounds more like a case of hardware failure so you will need to take your phone back to your point of purchase...if they are being less than helpful, then you will need to take your phone to your local Nokia Care for inspection: http://nokia.com/support

Maybe you are looking for

  • Address book sync issues

    Hi, I just added a new group within my MAC (10.4.10) Address Book (4.0.5) and when trying to sync it with my iPhone (1.0.2) , iTunes (7.3.2) always shows only the old groups - not the new one. Here is what I did so far to try to make it work: - Reset

  • PC Suite Backup failed to backup contacts

    Went to update my firmware today, and it said that it would delete all contents on my phone. So, I updated PC Suite, and then clicked the backup button. It appeared to be successful. I then had it install the firmware update. After that successfully

  • XI system configuration

    Hi all, My department got new server with XI installed. As our IT-support team is unavailable at the moment, I was told to configure installed XI server. And now I'm completely embarrassed - I studied to use XI, but not to configure the system. Can a

  • Report over two tables with shuttle seperated values listed per row

    Hy, I have created an application with 3 Tables: products (P_ID), applications(A_ID), crosstable (ID, A_ID, P_ID) for the assignment. In the app it´s possible to define the involved products for each application. Now I need a summary page, where all

  • PM SHOP PAPERS

    Hi PM Gurus, We have a problem while printing shop papers through t code IW3D. There are 2 shop papers for the order. First paper prints the long text also but second shop paper does not. Can anyone tell if there is any setting in config which allows