0

I am looking to out put a max and min date/time for each week. there are multiple entries in my table for each week.

Here is some example date

Week   Date
1      2013-02-01 10:10:23
1      2013-04-12 09:23:00
1      2013-04-13 12:23:00
2      2013-01-21 08:10:00
2      2013-04-12 09:23:45
2      2013-04-12 03:33:12

The output I am looking for is

week         Max Date              Min Date
1         2013-04-13 12:23:00        2013-02-01 10:10:23
2         2013-04-12 09:23:45        2013-01-21 08:10:00

Any help on where too begin would be great. Thank You.

4

1 回答 1

1

You will need to use an aggregate function with a GROUP BY. This applies both the min() and max() aggregates to the date column and groups by the week:

select week,
  max(date) max_date,
  min(date) mind_date
from yourtable
group by week;

See SQL Fiddle with Demo

于 2013-06-24T17:15:20.893 回答