1

我有一张这样的桌子。

+------------+-------------+--------------+
| name       | hobby       | hobby_number |
+------------+-------------+--------------+
| jack       | sport       | 1            |
| marco      | skydiving   | 3            |
| alfonso    | driving     | 1            |
| marco      | learning    | 2            |
| jack       | dancing     | 2            |
+------------+-------------+--------------+

我想使用 sql select 语句只选择一个唯一的名称。
我想要的表可能如下所示:

+------------+-------------+--------------+
| name       | hobby       | hobby_number |
+------------+-------------+--------------+
| jack       | sport       | 1            |
| marco      | learning    | 2            |
| alfonso    | driving     | 1            |
+------------+-------------+--------------+

sql查询应该是什么?

先感谢您。

4

1 回答 1

3
select t.* from your_table t
inner join
(
    select name, min(hobby_number) as minh
    from your_table
    group by name
) x on x.name = t.name and x.minh = t.hobby_number
于 2013-09-18T11:00:36.533 回答