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'

1
  • So let me clarify, for each row you have multiple fields you'd like to sum, but depending on conditions on that row, you'd only like to add some of those fields to the sum, or? ...actually, could you just post an example of some data and the results you'd like? Commented Jun 1, 2010 at 9:36

1 Answer 1

1

Sure!

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

Sign up to request clarification or add additional context in comments.

1 Comment

Will that give a row specific value as opposed to a value for the entire result array?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.