Hi,I've made a simple database containing football results, with goals scored and conceded, etc. I'm trying to make a query which will display a certain number of results in date order for a selected team; I've got it working for the last x home or away games but am not sure how to go about putting these queries together so to speak... perhaps with a Case statement? Or sub selects?Not after anyone doing it for me (unless they want to ;)) but a nudge in the right direction would be great. The queries I've got so far are below:SELECT Hometeam As Opponents, FTAG AS Scored, FTHG AS Conceded, FTAG - FTHG AS Difference FROM (SELECT TOP 5 * FROM Gamblor.dbo.prem Where awayteam = 'Aston Villa' order by Date desc) as away
SELECT Awayteam As Opponents, FTHG AS Scored, FTAG AS Conceded, FTHG - FTAG AS Difference FROM (SELECT TOP 5 * FROM Gamblor.dbo.Prem Where hometeam = 'Aston Villa' order by Date desc) as home
USE [Gamblor]GO/****** Object: Table [dbo].[Prem] Script Date: 02/29/2012 21:00:26 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOCREATE TABLE [dbo].[Prem]( [Div] [nvarchar](255) NULL, [Date] [date] NULL, [HomeTeam] [nvarchar](255) NULL, [AwayTeam] [nvarchar](255) NULL, [FTHG] [float] NULL, [FTAG] [float] NULL, [FTR] [nvarchar](255) NULL, [HTHG] [float] NULL, [HTAG] [float] NULL, [HTR] [nvarchar](255) NULL, [Referee] [nvarchar](255) NULL, [HS] [float] NULL, [AS] [float] NULL, [HST] [float] NULL, [AST] [float] NULL, [HF] [float] NULL, [AF] [float] NULL, [HC] [float] NULL, [AC] [float] NULL, [HY] [float] NULL, [AY] [float] NULL,
[float] NULL, [AR] [float] NULL ) ON [PRIMARY]GO/****** Object: View [dbo].[Premteams] Script Date: 02/29/2012 21:00:28 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOCREATE VIEW [dbo].[Premteams]ASSELECT DISTINCT HomeTeam AS teamFROM dbo.PremGO
insert into gamblor.dbo.Prem values('E0', 2012-01-14, 'Aston Villa', 'Everton', 1, 1, 'D', 0, 0, 'D', 'M Clattenburg', 17, 7, 11, 4, 12, 11, 9, 3, 1, 1, 0, 0)Please let me know if I've described anything in the wrong way, or missed anything useful out. What I'd like to be able to do is retrieve , say, the last 10 games where the chosen team is either the home or away side. And switch the conceded/scored values respectively so they're still correct.-Thanks in advance-