我在数据库中有以下系列:
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
有两种简单的方法:
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
您可以使用sql选择所有唯一的记录
select distinct column from table order by column;