Ver Mensaje Individual
  #2 (permalink)  
Antiguo 07/06/2013, 08:43
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: me ayudan con la 2° parte de este query?

teniendo tus datos podemos hacer esto:


Código SQL:
Ver original
  1. CREATE TABLE #temp
  2. (
  3. actividad VARCHAR(20),
  4. horario datetime,
  5. total INT
  6. )    
  7.  
  8.  
  9. INSERT INTO #temp VALUES ('Jugar','04-JUN-2013 11:00:00',2)
  10. INSERT INTO #temp VALUES ('Trabajar','04-JUN-2013 11:00:00',3)
  11. INSERT INTO #temp VALUES ('Trabajar','04-JUN-2013 12:00:00',4)
  12. INSERT INTO #temp VALUES ('Descansar','04-JUN-2013 12:00:00',4)
  13. INSERT INTO #temp VALUES ('Jugar','04-JUN-2013 13:00:00',1)
  14. INSERT INTO #temp VALUES ('Jugar','04-JUN-2013 13:00:00',3)
  15.    
  16.    
  17. SELECT #temp.actividad,total,g_total,CAST(total / CAST(g_total AS DECIMAL(10,4)) AS DECIMAL (10,4)) AS porce  FROM #temp    
  18. LEFT JOIN (SELECT SUM(total) g_total,horario FROM #temp GROUP BY horario) t1
  19. ON (t1.horario=#temp.horario)

saludos!
__________________
What does an execution plan say to t-sql query? Go f**k yourself, if you are not happy with me