根据排序密钥获取特定值(SQL)

时间:2017-02-23 08:48:40

标签: sql

我想按排序键获得5个唯一值。 以下是表格示例: -

enter image description here

预期结果为5,10,3,9,1。来自表格的第一个唯一5值。 感谢。

3 个答案:

答案 0 :(得分:2)

您可以对Oracle执行以下操作:

select * from (
    select value
    from table
    group by value
    order by min(serial) 
) where rownum <=5

答案 1 :(得分:1)

试试这个(对于MySQL ):

SELECT DISTINCT value FROM <table-name> ORDER BY serial LIMIT 5;

答案 2 :(得分:0)

对于SQL Server

select TOP 5 value   from table1
group by value
order by min(Serial)

enter image description here