2017-07-13 44 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; 
相关问题