SQL备忘

1. sum()

    SUM(show_cnt) OVER (ORDER BY show_cnt DESC) AS acc_show_cnt, --逐行累计

    SUM(show_cnt) OVER () AS total_show_cnt--全部累计

2. sql提取中文,并计算字符长度

length(regexp_replace(title, '[^\u4e00-\u9fa5]', '')) AS chinese_chars_count

3. 想要把30行的结果sum起来

SUM(cnt) OVER (

            ORDER BY

                    dt ROWS BETWEEN 29 PRECEDING

            AND    CURRENT ROW

        ) AS cnt_sum

你可能感兴趣的:(SQL备忘)