1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[SQL] Why I had to typecast in order to get floatvalue while solving this leetcode problem...

Discussão em 'Outras Linguagens' iniciado por Stack, Outubro 9, 2024 às 08:52.

  1. Stack

    Stack Membro Participativo

    SQL Server https://leetcode.com/problems/confirmation-rate/description/?envType=study-plan-v2&envId=top-sql-50

    select s.user_id,round(avg(cast(case when c.action='confirmed' then 1 else 0 end as float) ),2) as confirmation_rate
    from Signups s
    left join Confirmations c
    on s.user_id=c.user_id
    group by s.user_id


    ultimately the above solution worked but if you remove the type cast from same solution it starts failing and giving out rounded integers hence wrong answers

    since avg function is already there i thought it should be giving float values already but why it didnt i dont understand

    Continue reading...

Compartilhe esta Página