开发者

How to Find Single Row Records from Two Rows Data with AttTime in SQL Server

开发者 https://www.devze.com 2023-04-12 03:34 出处:网络
I have query to find Records in to single records from two rows withFirst AttTimeand Last AttTime using SQL Server 2005

I have query to find Records in to single records from two rows with First AttTime and Last AttTime using SQL Server 2005

My AttLog Table Structure is:

EnrollNo    Int
AttDate     DateTime
AttMonth    Int
AttDay      Int
AttYear     Int
AttTime     Varchar

Current output:

EnrollNo     AttDate               AttMonth   AttDay   AttYear   AttTime
405  2011-03-09 09:59:00.000       9          3        2011      9:59     
405  2011-03-09 18:40:00.000       9          3开发者_如何学运维           2011   18:40  

Desired output:

EnrollNo     AttDate               AttMonth   AttDay   AttYear   FirstTime   Last Time  
405  2011-03-09 09:59:00.000        9        3          2011      9:59        18:40


Assuming you are grouping records with same EnrollNo, you should use aggregate functions

  SELECT EnrollNo, Min(AttDate), Min(AttMonth), Min(AttDay), Min(AttYear), Min(AttTime) as FirstTime, Max(AttTime) as LastTime    
  FROM AttLog
  GROUP BY EnrollNo
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号