Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
spooke
Starting Member
7 Posts |
Posted - 2012-01-08 : 00:26:16
|
| Hi guys I am creating a database called bets and I am wondering if anyone can help me. In my table I have columns for Date, [Team one], [Team two], [Team one score], [team two score] and so on.If I want to list all the games that team two has won against team one and then list the date, team names, scores and the rest of the row how would I go about doing this?I know I need to somehow find all team two scores > team one scores and then list the rows however I am new to sql and don't know how to do such things... any help would be good. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-01-08 : 02:19:53
|
sounds like thisSELECT Date,CASE WHEN [Team one score]> [team two score] THEN [Team one] WHEN [Team one score]< [team two score] THEN [Team two] ELSE 'Tied' END AS WinnerFROM table ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
spooke
Starting Member
7 Posts |
Posted - 2012-01-08 : 02:52:51
|
| Hi Visakh,That's it except I only want to display the games that Team One looses, I tried removing part of the code so it looks like this:CASE WHEN [Team one score]< [team two score] THEN [Team two] END AS WinnerHowever the entries where [Team One] win now show up as Null. I dont want them there at all... can you help? |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-01-08 : 03:23:22
|
| [code]SELECT Date,CASE WHEN [Team one score]> [team two score] THEN [Team one] WHEN [Team one score]< [team two score] THEN [Team two] ELSE 'Tied' END AS WinnerFROM tableWHERE [team two score] > [Team one score][/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|