Data update

This commit is contained in:
Ingy döt Net 2025-08-11 18:05:26 -07:00
parent 4d5544505c
commit 4924dd0264
3073 changed files with 55820 additions and 4408 deletions

View file

@ -0,0 +1,10 @@
# lst should be a DuckDB list
create or replace function mode(lst) as (
with cte as (
SELECT number, COUNT(*) as frequency
FROM (SELECT unnest(lst) as number)
GROUP BY number
ORDER BY frequency DESC
LIMIT 1)
(select number from cte) -- signal that the result is scalar
);

View file

@ -0,0 +1 @@
select [1, 2, 2, 3, 3, 3, 4] as list, mode(list) as mode;

View file

@ -0,0 +1,10 @@
create or replace function modal_values(lst) as table (
with cte as (
SELECT number, COUNT(*) as frequency
FROM (SELECT unnest(lst) as number)
GROUP BY number )
select number
from cte
where frequency = (SELECT MAX(frequency) FROM cte)
order by number
);

View file

@ -0,0 +1 @@
select median(n) as mode from modal_values( [1,1,1,2,2,2,3]) t(n);

View file

@ -0,0 +1,15 @@
# Find the mode of a column named values in the named table
# by taking the median() of the modal values
create or replace function mode_of_column(TableName) as (
with cte as (
SELECT value, COUNT(*) as frequency
FROM query_table(TableName)
GROUP BY value
),
modal_values as (
SELECT value
from cte
where frequency = (SELECT MAX(frequency) FROM cte)
order by value
) select median(value) from modal_values
);

View file

@ -0,0 +1,2 @@
with cte as (select val as value from averages)
select mode_of_column('cte') as 'mode of val';

View file

@ -29,7 +29,7 @@ public program()
var array2 := new int[]{1, 3, 6, 6, 6, 6, 7, 7, 12, 12, 17};
var array3 := new object[]{1, "blue", 2, 7.5r, 5, "green", "red", 5, 2, "blue", "white"};
console
Console
.printLine("mode of (",array1.asEnumerable(),") is (",array1.Mode,")")
.printLine("mode of (",array2.asEnumerable(),") is (",array2.Mode,")")
.printLine("mode of (",array3.asEnumerable(),") is (",array3.Mode,")")