l******9 发帖数: 579 | 1 On SQL server 2008 R2, I would like to select one value of a column for each
distinct value of another column.
e.g.
name id_num
Tom 53
Tom 60
Tom 27
Jane 16
Jane 16
Bill 97
Bill 83
I need to get one id_num for each distinct name, such as
name id_num
Tom 27
Jane 16
Bill 97
For each name, the id_num can be randomly picked up as long as it is
associated with the name.
For example, for Bill, I can pick up 97 or 83. Either one is ok.
I do know how to write the SQL query.
Thanks | d*****5 发帖数: 1920 | 2 select name, min(id_num) from tableName group by name; |
|