Cita:
Empezado por keyboy
¿Y no has considerado la sugerencia que te hizo Neftali en el segundo mensaje?
Podrías tener un sólo DBGrid con una columna para cada fecha, haciendo muy fácil la comparación visual
y sin ener que recurrir a trucos raros.
Bye
|
Osea, que tendria que hacer un SELF-JOIN, porque deberia unir la tabla consigo misma.
tengo 2 tablas: CATEGORIAS y CAJA y consulto ambas en un año y otra en otro año (year(fecha)=xxxx), para compararlas
osea, ejecuto esto:
Código SQL
[-]select categoria, (select sum(debe) from caja t
where t.categoria=a.categoria and year(t.fecha)=2008) as egreso,
(select sum(haber) from caja t where t.categoria=a.categoria and year(t.fecha)=2008)
as ingreso from parapersonales a
y con la otra, lo mismo pero distinta fecha.
Lo que no me doy cuenta, donde meter el JOIN (sobre la misma tabla)
Código SQL
[-]select categoria,
(select sum(debe) from caja t where t.categoria=a.categoria and year(t.fecha)=2008) as egreso,
(select sum(haber) from caja t where t.categoria=a.categoria and year(t.fecha)=2008) as ingreso
from parapersonales a INNER JOIN (select categoria,
(select sum(debe) from caja u where u.categoria=b.categoria and year(u.fecha)=2007) as egreso,
(select sum(haber) from caja u where u.categoria=b.categoria and year(u.fecha)=2007) as ingreso
from parapersonales b)



......


