前提條件:
使用偽劣實現,對現有的信息進行分組添加序號。
create table if not EXISTS bigdata.test (id int ,name varchar(255), num int); insert into test VALUES(1,'lili-1', 1); insert into test VALUES(1,'lili-2', 2); insert into test VALUES(1,'lili-3', 3); insert into test VALUES(2,'lu-1', 1); insert into test VALUES(2,'lu-2', 2); insert into test VALUES(2,'lu-3', 3); select * from test where num in (1,2) order by id,num;
-- 過濾num列中想要的信息即可。
-- 如果只想獲取每組的第一行,可以直接分組實現
-- 如果只想獲取每組中前兩行,where后過濾1,2即可。
-- 如果想獲取指定列信息,直接在where后添加即可
表信息:
結果: