Ver Mensaje Individual
  #4 (permalink)  
Antiguo 24/07/2013, 08:51
Avatar de Libras
Libras
Colaborador
 
Fecha de Ingreso: agosto-2006
Ubicación: En la hermosa perla de occidente
Mensajes: 7.412
Antigüedad: 17 años, 8 meses
Puntos: 774
Respuesta: Obtener el valor de un campo que es el máximo en otro campo (soy novato)

Código SQL:
Ver original
  1. CREATE TABLE #temp
  2. (
  3. fecha datetime,
  4. divisa VARCHAR(20),
  5. cotizacion INT
  6. )
  7.  
  8. INSERT INTO #temp VALUES ('2013-28-02 00:00:00.000',    'USD',  1308404)
  9. INSERT INTO #temp VALUES ('2013-31-01 00:00:00.000',    'USD',  1352393)
  10. INSERT INTO #temp VALUES ('2012-31-12 00:00:00.000',    'USD',  1321807)
  11. INSERT INTO #temp VALUES ('2012-30-11 00:00:00.000',    'USD',  1296664)
  12. INSERT INTO #temp VALUES ('2012-31-10 00:00:00.000',    'USD',  1293678)
  13. INSERT INTO #temp VALUES ('2012-30-09 00:00:00.000',    'USD',  1286041)
  14. INSERT INTO #temp VALUES ('2012-31-08 00:00:00.000',    'USD',  1253196)
  15. INSERT INTO #temp VALUES ('2007-15-11 00:00:00.000',    'CHF',  1623943)
  16. INSERT INTO #temp VALUES ('2007-18-09 00:00:00.000',    'CHF',  1624439)
  17. INSERT INTO #temp VALUES ('2000-01-01 00:00:00.000',    'CHF',  1423710)
  18. INSERT INTO #temp VALUES ('2008-25-08 00:00:00.000',    'GBP',  0786543)
  19.  
  20.  
  21. SELECT * FROM #temp WHERE fecha IN (SELECT MAX(fecha) FROM #temp GROUP BY divisa)
__________________
What does an execution plan say to t-sql query? Go f**k yourself, if you are not happy with me