views:

30

answers:

1

I'm trying to query a database, and return a set of values. Part of the data i'm trying to return is an insurance premium breakdown.

Is it possible to run a query, that selects multiple fields, then adds then and returns them as a single value?

I've seen SUM() but the examples i've seen show it as adding up the results of an entire field - where as i need it to add specific fields for each row returned.

Any help is much appreciated.

EDITED

Here's an example query:

Doesn't work, it seems to add the entire result array up.

Here's what i'm trying to achieve:

SELECT custom_data.customReference AS Our_Ref, policy_details.policyNumber AS Policy_Number, policy_details.policyInception AS Start_Date, premium_breakdown.premium AS Cost_To_Customer
FROM custom_data_customReference, policy_details, premium_breakdown
WHERE policy_details.policy_details_id = premium_breakdown.policy_details_id AND policy_details.policy_details_id = custom_data.policy_details_id

Basically, each row contains the details of a specific insurance policy for which, we have a premium breakdown. What I want to do, is add up some values of the breakdown to give a 'Cost To Broker'

A: 

Sure!

SELECT (sum(amount1) + sum(amount2)) AS sum FROM insurance WHERE ???

Odelya
Will that give a row specific value as opposed to a value for the entire result array?
Sjwdavies
Just change the ??? to your condition.for example: where age >20
Odelya