Home > Archive > MySQL ODBC Connector > January 2006 > Again Doubt on Query pls help (Doubt not cleared)









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Again Doubt on Query pls help (Doubt not cleared)
Veerabhadrarao Narra

2006-01-28, 7:23 am

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.




--
veerabhadrarao narra,
+91-988-556-5556
I-ONE TECH LABS Pvt Ltd.
HYDERABAD, INDIA


--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql? unsub...sie.nctu.edu.tw

Juan Pedro Reyes Molina

2006-01-28, 9:23 am

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
>
>
> 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/mysql? unsub...sie.nctu.edu.tw

Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2009 droptable.com