Richa Garg

Richa Garg

  • NA
  • 10.9k
  • 4.9m

How to combine a multiple rows in Sql 2005?

Aug 16 2012 12:27 AM
Suppose my database is looks like,

id       name                    date                                              status
1          A           2012-07-16 13:54:02.000                          Login
1          A           2012-07-16 13:54:35.000                          Logout
1          A            2012-07-16 14:21:22.000                          login
1          A             2012-07-16 14:21:36.000                         logout
2          B              2012-07-16 14:21:53.000                        LOGIN
2          B             2012-07-16 14:41:54.000                        LOGOUT

AND I want a output like

id           name          date                         login_period
1             A               2012-07-16               (differnece b/w the login and logout time total)
2             B               2012-07-16                (difference b'w the login and logout time)

How can I do this .Please help me out.

Answers (5)