sql 计算auc

https://tracholar.github.io/machine-learning/2018/01/26/auc.html

select
    (ry - 0.5*n1*(n1+1))/n0/n1 as auc
from(
    select
        sum(if(y=0, 1, 0)) as n0, --50
        sum(if(y=1, 1, 0)) as n1,--100
        sum(if(y=1, r, 0)) as ry --100
    from(
        select y, row_number() over(order by score asc) as r
        from(
            select y, score
            from some.table
        )A
    )B
)C

原文地址:https://www.cnblogs.com/fujian-code/p/10644483.html