-1

我在数据库中有以下系列:

9, 10, 10, 12, 12, 13, 15, 15, 18, 18, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28

我想让它们都独一无二(因为它们应该是)。谁能建议解决这个问题的最佳方法是什么?使用 php 代码是可以的(也是首选),但我不能手动执行此操作,因为我的数据库中有数百万行。为了更清楚一点,结果系列应如下所示:

9, 10, 11, 12, 13, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30
4

2 回答 2

2

有几种简单的方法可以做到这一点:

SELECT DISTINCT the_number_column
FROM your_table
ORDER BY the_number_column;

或者:

SELECT the_number_column
FROM your_table
GROUP BY the_number_column
ORDER BY the_number_column;

最小的性能差异(至少使用 Oracle):http ://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:32961403234212

于 2012-12-28T00:52:02.493 回答
1

您可以使用 sql 选择所有唯一的记录

select distinct column from table order by column;
于 2012-12-28T00:53:08.843 回答