使用 SQL 查询设置概率

Hir*_*ren 1 sql

我有一张如下表:

    Number   Occurrence
     1         12
     2         30
     3         15
     4         20
Run Code Online (Sandbox Code Playgroud)

我想根据每个数字的出现计算概率,然后想得到概率最高的数字。

我想要这个 SQL 查询。

Joe*_*lli 5

SELECT Number, Occurance, 
       Occurance*1.0/(SELECT SUM(Occurance) FROM YourTable) AS Probability
    FROM YourTable
    ORDER BY Occurance DESC
Run Code Online (Sandbox Code Playgroud)