Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

getting totals

Status
Not open for further replies.

jvande

MIS
Jun 6, 2001
115
US
What is the best way to get totals for Field1,2?
Select Field1,Field2,Field3,sum(field2) as sum_field1,sum(field2) as sum_field2
from table1
where field1='test'
 
You can't mix columns and aggregate functions without using a group by clause, so your query is invalid.

Also, sum is not applicable on char columns.

To get the # of occurences for a certain crietria

Code:
select count(*) from table1 where field1 = 'test'

What are you trying to accomplish?
 
I have a huge query that I want the sum of a one of a couple of the fields in my select statement.
 
sorry my first post was incorrect.
What is the best way to get totals for Field2 and field3?
Select Field1,Field2,Field3,sum(field2) as sum_field1,sum(field2) as sum_field2
from table1
where field1='test'
 
We'll say it again - you need a group by clause, and not only that, ALL the fields have to be grouped.

Select Field1,Field2,Field3,sum(field1) as sum_field1,sum(field2) as sum_field2,sum(field3) as sum_field3 from table1 where field1='test' group by Field1,Field2,Field3

would work.



Mike Krausnick
Dublin, California
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top