简体   繁体   中英

How do I do a second group (rank) within a set of records?

Here is an example of the data- Example

First rank is done based on event_time ascending.

After the first ranking I need record 2 to record 6 be ranked as 1 and rec7 to 17 as 2. Can this be achieved in snowflake db?

you can use the case statement and have the values as follows.

# I need record 2 to record 6 be ranked as 1 and rec7 to 17 as 2.

    select
        column1,
        case 
            when column1 > 2  and column1 < 6 then 1
            when column1 > 6 and column1 < 18  then '2'
             else '0'
        end as new_col
    from values (3), (4), (3), (17);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2025 STACKOOM.COM