我试过group by
了,但是每个account_id我只会得到1个,我想要每个account_id 10个。这就是我要找的东西。
SELECT id,account_id FROM whatever {LIMIT to 10 of each account_id}
我试过group by
了,但是每个account_id我只会得到1个,我想要每个account_id 10个。这就是我要找的东西。
SELECT id,account_id FROM whatever {LIMIT to 10 of each account_id}
您可以对每个 account_id、id 组使用 rank
例子:
SELECT id,account_id FROM (
SELECT id,account_id,
@acrank:=CASE
WHEN @aid <> id THEN 1
ELSE @acrank+1 END AS rn,
@id:=id AS id_set
FROM
(SELECT @acrank:= -1) nr,
(SELECT @id:= -1) n,
(SELECT * FROM Test ORDER BY id, account_id) t
) x WHERE rn < 11