You can convert this query for example to optimize over for a consultation, is to get you up depending on the version, it's the same table.
select MAX(y.Version),
y.Unidad,
y.RutCompañia,
y.Cobertura,
y.Temporada,
y.PorcentajeSubsidio,y.RendimientoInferior,y.RendimientoSuperior
from ddbb.dbo.NS_CA y
where y.IDVariedad='010101' and y.Temporada ='2011'
and y.ZHS='CA0607'
and y.Moneda='UF'
and y.Version in (select MAX(x.Version) from ddbb.dbo.NS_CA x where x.IDVariedad='010101' and x.Temporada ='2011'
and x.ZHS='CA0607'
and x.Moneda='UF')
group by y.Unidad,y.RutCompañia,y.Cobertura,y.Temporada,y.PorcentajeSubsidio,y.RendimientoInferior,y.RendimientoSuperior
I imagined something like this
select MAX(b.Version) OVER(PARTITION BY b.IDVariedad,b.IDRubro ) as maximo
but it does not work properly
Thank you.
EDIT:
Thanks for you translate and answers. Add more info , by example i have next table (tabla) :
| Version | Temporada | Unidad | etc |
|:-----------|------------:|:------------:|:------------:|
| 00 | 2011 | N | xx |
| 00 | 2011 | N | xx |
| 01 | 2011 | N | xx |
| 02 | 2011 | N | xx |
| 03 | 2011 | N | xx |
| 03 | 2011 | N | xx |
and query i would generate is :
select * from tabla a
where a.version in (select max(b.Version) from tabla b where b.Temporada='2011')
| Version | Temporada | Unidad | etc |
| 03 | 2011 | N | xx |
| 03 | 2011 | N | xx |
is possibility change sub-query to 'over partition' ? , thanks