I think this is what you want to do:
SELECT t1.Division,t1.year, t1.units this_year_units, t2.units
last_year_units, case when t2.units is null then t1.units else
(t1.units-t2.units) end as Difference_Units
FROM `narra_table` t1 left join narra_table t2
on (t1.Division=t2.Division) and (t1.Year=t2.Year+1)
hope this helps
Veerabhadrarao Narra wrote:
i have to write one query
Division Units Year
a 200 2004
a 300 2005
b 500 2004
b 800 2005
b 900 2006
c 100 2004
From these values i want to retreive as like this
Division Units Year
a 200 2004
a 100 2005
b 500 2004
b 300 2005
b 100 2006
c 100 2004
Group By division names and year with difference.
Means difference of the Units values by year can u give me this query.
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]