Q
Problem solve Get help with specific problems with your technologies, process and projects.

Can you sum one field in a list of fields?

Can you sum one field in a list of fields? i.e.

SELECT 
job_line_discount.disc_id,
job_line_discount.disc_amt,
sum(job_actual_cost.progress_bill_amt) as pamount
FROM
  job,
  job_actual_cost     job_line_discount

Something's not quite right with that syntax. It looks like there should be a comma between the last two names in the FROM clause; otherwise, job_line_discount will be an alias for job_actual_cost. Based on what's in your SELECT list, those are probably separate tables.

To answer your question, yes, you can sum one field in a list of fields, but then all other fields that are not used in an aggregate function like SUM() must be listed in the GROUP BY clause --

select job_line_discount.disc_id
     , job_line_discount.disc_amt
     , sum(job_actual_cost.progress_bill_amt) as pamount
  from job
     , job_actual_cost
     , job_line_discount
group by
       job_line_discount.disc_id
     , job_line_discount.disc_amt

Presumably, there will also be a WHERE clause, between the FROM and GROUP BY. Otherwise you'll get a cross join, and you probably don't want that.

For More Information


This was last published in June 2002

Dig Deeper on Oracle and SQL

PRO+

Content

Find more PRO+ content and other member only offers, here.

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

-ADS BY GOOGLE

SearchDataManagement

SearchBusinessAnalytics

SearchSAP

SearchSQLServer

TheServerSide

SearchDataCenter

SearchContentManagement

SearchFinancialApplications

Close