在分组中使用列名或者列号,但不要混合使用

未匹配的标注
-- Good
select user_id, count(*) as total_charges
from charges
group by user_id

-- Good
select user_id, count(*) as total_charges
from charges
group by 1

-- Bad
select
    timestamp_trunc(created_at, month) as signup_month,
    vertical,
    count(*) as users_count
from users
group by 1, vertical

本文章首发在 LearnKu.com 网站上。

上一篇 下一篇
讨论数量: 0
发起讨论 只看当前版本


暂无话题~