Sbhn_NPValidators Number of Vote Changes
    Updated 2022-12-15
    --credit : misaghlb
    with cosmos_fact_governance_votes as (
    select a.block_timestamp,
    a.tx_id,
    b.ATTRIBUTE_VALUE::string as voter,
    a.TX_SUCCEEDED,
    a.attribute_value as PROPOSAL_ID,
    TRY_PARSE_JSON(c.attribute_value):weight as VOTE_WEIGHT,
    TRY_PARSE_JSON(c.attribute_value):option as VOTE_OPTION,
    case
    when TRY_PARSE_JSON(c.attribute_value):option = '1' then 'Yes'
    when TRY_PARSE_JSON(c.attribute_value):option = '3' then 'No'
    when TRY_PARSE_JSON(c.attribute_value):option = '4' then 'No with Veto'
    when TRY_PARSE_JSON(c.attribute_value):option = '2' then 'Abstain'
    else null end as VOTE_OPTION_STRING

    from cosmos.core.fact_msg_attributes a
    join cosmos.core.fact_msg_attributes b on a.tx_id = b.tx_id and b.ATTRIBUTE_KEY = 'sender' and b.MSG_TYPE = 'transfer'
    join cosmos.core.fact_msg_attributes c on a.tx_id = c.tx_id and c.ATTRIBUTE_KEY = 'option' and c.MSG_TYPE = 'proposal_vote'
    where a.msg_type = 'proposal_vote'
    and a.attribute_key = 'proposal_id'
    and VOTE_OPTION_STRING is not NULL
    -- and a.tx_id = 'D75C29F9A170966846719302A0DD108F8D372436633C8CA31002A32DB3FCE1B3' -- sample vote
    ),
    vote_changing_data as (
    select
    *,
    lead(VOTE_OPTION_STRING, 1) over (partition by VOTER order by block_timestamp ASC) as VOTE_OPTION_STRING_2,
    VOTE_OPTION_STRING || ' => ' || VOTE_OPTION_STRING_2 as changed
    from cosmos_fact_governance_votes
    join cosmos.core.fact_validators on voter = account_address
    where TX_SUCCEEDED = 'TRUE'
    and proposal_id = '82'
    order by block_timestamp ASC
    )
    Run a query to Download Data