Connecting Tech Pros Worldwide Help | Site Map

get grand total

Familiar Sight
 
Join Date: Oct 2008
Posts: 128
#1: Sep 18 '09
how to get grand total of two years 2001,2002 are fields
Expand|Select|Wrap|Line Numbers
  1. SELECT sum( 2001 ) AS "2001-2002", sum( 2002 ) AS "2002-2003", (
  2. "2001-2002" + "2002-2003"
  3. ) AS "grand total"
  4.  
  5. FROM school
this query has error
Atli's Avatar
Moderator
 
Join Date: Nov 2006
Location: Iceland
Posts: 3,741
#2: Sep 18 '09

re: get grand total


Hi.

What error are you getting?

How exactly does your table look like?
(The relevant parts of it, at least.)
Familiar Sight
 
Join Date: Oct 2008
Posts: 128
#3: Sep 22 '09

re: get grand total


table is like this
schoolid,schoolname,2001(grant),2002(grant)
i want to get total grant of 2001 then i want to get total grant of 2002 then grant total of both totals (tot2001+tot2002)
all three in same row
Atli's Avatar
Moderator
 
Join Date: Nov 2006
Location: Iceland
Posts: 3,741
#4: Sep 22 '09

re: get grand total


How about the error?
What exactly is going wrong with the query?

You should keep in mind tho, that in a query like that, numbers will not be interpreted as column names. If you have column names that are numbers, they must be enclosed in back-ticks (`).

Also, you can not use the aliases for the first two columns to get the sum for the third one. You would have to use the actual column names.
Reply