🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: bit.listserv.sqlinfo
Article #223

sql query

#223
From: Dan Matthews
Date: Sun, 30 Jul 2000 00:00
37 lines
2003 bytes
Hi.

I have a problematic query which  cant get right. The query builds a league
table of team names and respective points. Could someone tell me the correct
way to add the penalty information on to the points totals for each team?

original query >>

SELECT v.Name AS Team, Sum(r.Points) AS TeamTotal
FROM VF1Team AS v, TeamPicks AS t, Driver AS d, RaceResults AS r, venue
WHERE (((v.ID)=[t].[teamid]) AND ((t.driverID)=[d].[id]) AND
((d.ID)=[r].[driverid]) AND ((r.VenueID)=[venue].[id]))
GROUP BY v.Name
ORDER BY Sum(r.Points) DESC;

---

attempt 1
========

SELECT v.Name AS Team, Sum(r.points + (SELECT vf1team.Penalty from vf1team
where vf1team.penalty is not null))
FROM VF1Team AS v, TeamPicks AS t, Driver AS d, RaceResults AS r, venue
WHERE (((v.ID)=[t].[teamid]) AND ((t.driverID)=[d].[id]) AND
((d.ID)=[r].[driverid]) AND ((r.VenueID)=[venue].[id]))
GROUP BY v.Name
ORDER BY Sum(r.Points) DESC;

attempt 2
=======

SELECT v.Name AS Team, Sum(r.points + V.Penalty)
FROM VF1Team AS v, TeamPicks AS t, Driver AS d, RaceResults AS r, venue
WHERE (((v.ID)=[t].[teamid]) AND ((t.driverID)=[d].[id]) AND
((d.ID)=[r].[driverid]) AND ((r.VenueID)=[venue].[id]))
GROUP BY v.Name
ORDER BY Sum(r.Points) DESC;
Technical Details
Message-ID: <8m0n6i$7jb$1@newsg2.svr.pol.co.uk>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 1131db,41944c61440e9517,start
X-Google-Attributes: gid1131db,public
X-Google-Thread: 11355a,41944c61440e9517,start
X-Google-Attributes: gid11355a,public
From: "Dan Matthews" <dan@grandprix.freeserve.co.uk>
Subject: sql query
Date: 2000/07/30
Message-ID: <8m0n6i$7jb$1@newsg2.svr.pol.co.uk>
X-Deja-AN: 652372357
X-Priority: 3
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.3018.1300
X-Complaints-To: abuse@theplanet.net
X-Trace: newsg2.svr.pol.co.uk 964943890 7787 62.136.196.196 (30 Jul 2000 07:58:10 GMT)
Organization: Customer of Energis Squared
X-MSMail-Priority: Normal
NNTP-Posting-Date: 30 Jul 2000 07:58:10 GMT
Newsgroups: bit.listserv.sqlinfo,mailing.database.sql-general