2017-07-13 74 views

回答

2

不要使用union小號!只需使用row_number()

select p.* 
from (select p.*, row_number() over (partition by color order by color) as seqnum 
     from product p 
    ) p 
where seqnum <= 2; 
+0

完美謝謝! – user1854438

1
select id, color, item 
from (select id, color, item, 
       row_number() over (partition by color order by null) as rn 
     from product 
     ) 
where rn <= 2; 
相關問題