tags:

views:

285

answers:

1

HOW TO DISPLAY FIRST AND LAST ROW VALUE FROM THE TABLE BY USING COUNT

EXAMPLE:

ID   TIME   DATE

001  10.00  02:10:2009 
001  02.00  02:10:2009 
001  23.00  02:10:2009 
002  04.00  03:10:2009 
002  12.00  03:10:2009 
002  22.00  03:10:2009 

SELECT ID, COUNT(*) AS TIME FROM TABLE

OUTPUT IS

ID      date       TIME

001   02:10:2009    3
002   03:10:2009    3

For 001 Time count is 3 Then time is 10.00, 02.00, 23.00 For 002 Time count is 3 Then time is 04.00, 12.00, 22.00

I want to display min(time) and Max(time) from the count value

Exactly i need

For 001 min(time) is 02.00 max(time) is 23.00 for the particular date

SQL Query?

+8  A: 

Try something like

select id, 
  count(*) as time_count, 
  min(time) as min_time, 
  max(time) as max_time 
from table
group by id, date;
Greg Reynolds