[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

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

Getting first min date value for each employee number

I need a SQL Statement to list the employee number and the minimum date value so for the examples listed below, so that I'd get the following result:

234418         2009-01-15
245717      2009-01-15

Example of data:
234418      2009-01-15 00:03:00.000
234418      2009-01-15 14:54:00.000
234418      2009-01-15 18:02:00.000
234418      2009-01-15 19:00:00.000
------
245717      2009-01-15 08:23:00.000
245717      2009-01-15 11:54:00.000
245717      2009-01-15 12:58:00.000
245717      2009-01-15 17:13:00.000
0
jeffrey_b_lee
Asked:
jeffrey_b_lee
  • 2
1 Solution
 
MohammedUCommented:
select empno, min(empdate)
from emp
group by empno
0
 
nmcdermaidCommented:
going by your example (all data is on the same day):
select distinct employeeid, convert(datetime,convert(varchar(8),datefield,112),112) as datefield
from yourtable

if however you have a number of days then this is mor useful:
select employeeid, min(convert(datetime,convert(varchar(8),datefield,112),112)) as datefield
from yourtable
group by employeeid
0
 
milduraitCommented:
Hi Jeffery

Something like this may suit your needs

SELECT
 EmpNo,  
 CAST(FLOOR(CAST(MIN(EmpDate) AS Float)) as EmpDate
FROM EmpTable
GROUP BY EmpNo
ORDER BY EmpNo
0
 
milduraitCommented:
..maybe another bracket on line 3

SELECT
 EmpNo,  
 CAST(FLOOR(CAST(MIN(EmpDate) AS Float))) as EmpDate
FROM EmpTable
GROUP BY EmpNo
ORDER BY EmpNo
0

Featured Post

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

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