Solved

working out  how to double sum of one round if rounds match

Posted on 2015-02-09
4
106 Views
Last Modified: 2015-02-09
Hi hope you can help I have a query

SELECT     SUM(res.points) AS points, f1.Driver1
FROM         races AS r INNER JOIN
                      results AS res ON r.raceId = res.raceId INNER JOIN
                      f1users AS f1 ON res.driverId = LEFT(f1.Driver1, 3)
WHERE     (r.year = 2014) AND (f1.submissionID = 51)
GROUP BY f1.Driver1, r.round

Open in new window


which show the total points for a year but what i now need is to double the points if r.round = f1.round  so at mo

it would show

701 Lewis Hamiltion

but new one would show

726 Lewis Hamilton as round 18 matches so he collects a extra 25 points
0
Comment
Question by:James Murrell
  • 2
4 Comments
 
LVL 69

Accepted Solution

by:
ScottPletcher earned 500 total points
Comment Utility
SELECT     SUM(res.points * CASE WHEN  r.round = f1.round THEN 1 ELSE 2 END) AS points, f1.Driver1
...
0
 
LVL 65

Expert Comment

by:Jim Horn
Comment Utility
Give us an example of 'double the points', as that's hard to read when the numbers are 701, 726, 18, and 25.
0
 
LVL 31

Author Closing Comment

by:James Murrell
Comment Utility
Thanks could not see the wood for the trees on that one
0
 
LVL 69

Expert Comment

by:ScottPletcher
Comment Utility
Not necessary instinctive, but now that you've seen that technique, you'll use it easily again in the future.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
INSERT INTO SELECT JOIN THING 2 24
Help in Understanding a SQL Query 7 24
Complex SQL 10 32
SQL JOIN 6 27
This article explains all about SQL Server Piecemeal Restore with examples in step by step manner.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how the fundamental information of how to create a table.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now