How to write a SQL Server query to summarise table data? -
i need sql server query. have table this:
user_id display_name username updated_on -------------------------------------------------------------------- 2012772 user1.username 450958885 2012772 user1.displayname 451124897 2155281 user2.username 451045840 2162145 user3.username 451147363 2162145 user3.displayname 451147423
and need output below: if display name user present render along updated_on else render username , updated on.
user_id display_name_computed updated_on ---------------------------------------------------- 2012772 user1.displayname 451124897 2155281 user2.username 451045840 2162145 user3.displayname 451147423
the sql should select statement. no temp tables or table variables usage. no delete statements usage.
here go
select user_id , coalesce(max(display_name), max(username)) display_name_computer , max(updated_on) updated_on yourtable group user_id
Comments
Post a Comment