Solved

MS Access Query to return sum of two fields multiplied by third field

Posted on 2013-01-14
4
428 Views
Last Modified: 2013-01-16
Hello,

I created the following query that returns a subset of data.  I'm having troubles extending it one step further.  The query should return a result of a calculation a single value.

 = (NumberOfDrivers + NumberClaims) X Result

SELECT LocationID, CarType, NumberDrivers, NumberClaims, Result FROM mydatabase WHERE CarType="Sedan";

Open in new window


Thanks
0
Comment
Question by:AndyC1000
  • 2
4 Comments
 
LVL 39

Accepted Solution

by:
Pratima Pharande earned 125 total points
ID: 38777140
try this

SELECT LocationID, CarType, NumberDrivers, NumberClaims, Result ,
((NumberOfDrivers + NumberClaims) * Result ) as new_result
 FROM mydatabase WHERE CarType="Sedan";
0
 

Author Comment

by:AndyC1000
ID: 38781347
Thanks for your reply.

The calculation returns a value although I realised the where clause will need to be changed to produce the correct value I need.  The value being returned is 113.174633402367 instead of 81.6263502 for the first location ID 3146701.

I would like the query to query all location ids, where car type equals sedan returning the calculation in a new field.

The attached excel sheet will hopefully help explain the scenario.  The bottom table is the output of the query required.

Thanks.
0
 

Author Comment

by:AndyC1000
ID: 38781354
Note I updated the query with the correct field names NumberDrivers1 and NumberClaims0.
Example-Table.xlsx
0
 
LVL 27

Assisted Solution

by:Lukasz Chmielewski
Lukasz Chmielewski earned 125 total points
ID: 38782059
Your calculation is based not on
 = (NumberOfDrivers + NumberClaims) X Result
but rather
 = NumberOfDrivers + (NumberClaims X Result)

altering prtima's code:
SELECT LocationID, CarType, NumberDrivers, NumberClaims, Result ,
(NumberOfDrivers + NumberClaims  * Result ) as new_result
 FROM mydatabase WHERE CarType="Sedan";

Open in new window

0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…

911 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

15 Experts available now in Live!

Get 1:1 Help Now