Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 295
  • Last Modified:

Aggregate function for DateTime variables??

I have a table that contains a DateTime column, and another column that I want to use as the group indicator.  I haven't found a function that will select the latest or earliest of the DateTime values for each group.  Does one exist?

Thanks
0
garyz31
Asked:
garyz31
1 Solution
 
spcmnspffCommented:
I'm not sure, but will this do what you described?

Latest Date for each group:

Select Group, Max(Date)
From Table
Group By Group


Earliest Date for each group:

Select Group, Min(Date)
From Table
Group By Group
0
 
SYASSINCommented:
you can also combine the two above...

select Group, max(date), min(date)
from Table
group by group
0
 
Mogalappa AdakiCommented:
suppose your datetime column is x and other columns are y,z

assing x as getdate() value in your program to get the date of the entry of record in the table.

select y,z,x from tablename order by x desc
0
 
garyz31Author Commented:
Thanks:  I got distracted from this project for quite a while.
0

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now