Benford's law on SO - improved

0

Please login or register to vote for this query.

(click on this box to dismiss)

Vegetarianism

Q&A for those committed to a vegan or vegetarian lifestyle and anyone interested in learning more

-- Benford's law on SO

SELECT firstDigit,
       COUNT(*) [Count],
       convert(decimal(5,2),100.0*COUNT(*)/SUM(COUNT(*)) OVER ()) Percentage,
       Benford.p Law
FROM
(
    SELECT LEFT(LEN(post.Body),1) as firstDigit
    FROM Posts as post
) [ ]
inner join
(   values
    (1, 30.1),   (2, 17.6),   (3, 12.5),
    (4, 9.7),    (5, 7.9),    (6, 6.7),
    (7, 5.8),    (8, 5.1),    (9, 4.6)
) Benford(d,p) on Benford.d = [ ].firstDigit
GROUP BY firstDigit, Benford.p
Order by firstDigit

Enter Parameters

Options:
Switch to meta site
loading Hold tight while we fetch your results