【发布时间】:2014-04-20 00:45:14
【问题描述】:
假设我有一个包含以下行的两列表 (t1):
id animal
---- ------
1 dog
1 pig
1 donkey
2 cow
2 horse
2 dog
2 donkey
现在,我只想为给定的 ID 保留一行。我可以做一个最小值或最大值以及一个分组:
create table t2 as (
select id, min(animal)
from t1
group by id
) with data unique primary index(id);
有没有办法为每个 id 获取随机行?比最小值或最大值更难以预测的东西。
【问题讨论】: