Open archiewood opened 1 year ago
Example of SQL and Component from source query to UI:
NOTE: I'm using duckdb-wasm
approach with source queries.
//sources/duckdb-sec/cik_cusip_per_qtr.sql
SELECT
quarter,
ANY_VALUE(CAST(SUBSTR(quarter, 1, 4) AS INTEGER) ||
CASE
WHEN quarter LIKE '%Q1' THEN '-03-31'
WHEN quarter LIKE '%Q2' THEN '-06-30'
WHEN quarter LIKE '%Q3' THEN '-09-30'
WHEN quarter LIKE '%Q4' THEN '-12-31'
END) AS quarter_end_date,
((quarter_end_date::date + INTERVAL '45 days'))::string AS last_reporting_date,
CASE WHEN now()::date > last_reporting_date THEN 'YES' ELSE 'NO' END AS is_quarter_completed,
COUNT(DISTINCT cik) AS num_ciks_per_quarter_num0,
COUNT(DISTINCT cusip) AS num_cusip_per_quarter_num0,
SUM(value)::bigint AS total_value_per_quarter_usd,
(SELECT COUNT(DISTINCT cik) FROM main.main WHERE accession_number != 'SYNTHETIC-CLOSE')::integer AS total_ciks_num0,
(SELECT COUNT(DISTINCT quarter[:4]) FROM main.main WHERE accession_number != 'SYNTHETIC-CLOSE' AND quarter > '1998Q1')::integer AS total_years,
(SELECT COUNT(DISTINCT quarter) FROM main.main WHERE accession_number != 'SYNTHETIC-CLOSE')::integer AS total_quarters,
ROUND((COUNT(DISTINCT cik) - LAG(COUNT(DISTINCT cik)) OVER (ORDER BY quarter)) / LAG(COUNT(DISTINCT cik)) OVER (ORDER BY quarter), 2) * 100 AS prc_change_cik,
ROUND((COUNT(DISTINCT cusip) - LAG(COUNT(DISTINCT cusip)) OVER (ORDER BY quarter)) / LAG(COUNT(DISTINCT cusip)) OVER (ORDER BY quarter), 2) * 100 AS prc_change_cusip,
ROUND((SUM(value) - LAG(SUM(value)) OVER (ORDER BY quarter)) / LAG(SUM(value)) OVER (ORDER BY quarter), 2) * 100 AS prc_change_total_value
FROM main.main
WHERE accession_number != 'SYNTHETIC-CLOSE' AND quarter > '1998Q1'
GROUP BY quarter
ORDER BY quarter DESC
//index.md """
select *
from cik_cusip_per_quarter
SELECT
t.year,
t.max_quarter_end_date,
q.num_ciks_per_quarter_num0,
q.num_cusip_per_quarter_num0,
q.total_value_per_quarter_usd AS total_value_per_quarter_usd
FROM (
SELECT
SUBSTR(quarter, 1, 4) AS year,
MAX(quarter_end_date) AS max_quarter_end_date
FROM cik_cusip_per_quarter
WHERE is_quarter_completed = 'YES'
GROUP BY year
) t
JOIN cik_cusip_per_quarter q
ON q.quarter_end_date = t.max_quarter_end_date
ORDER BY t.year;
<AreaChart
data={cik_cusip_per_quarter2}
x=year
y=total_value_per_quarter_usd
sort=asc
/>
"""
For LineChart with
usd
format