RosettaCodeData/Task/Currency/DuckDB/currency.duckdb
2025-08-11 18:05:26 -07:00

17 lines
656 B
Text

# Compute the required details in a table using DECIMAL(38,2) for dollars and cents.
create or replace function bill( quantities, prices, taxrate) as table (
with cte as (select sum(q*p) as subtotal
from (select unnest(quantities) as q, unnest(prices) as p)),
details as (select subtotal, subtotal * taxrate as tax,
(subtotal + tax ) as total
from cte)
select subtotal::DECIMAL(38,2) as subtotal,
tax::DECIMAL(38,2) as tax,
total::DECIMAL(38,2) as total
from details
) ;
# The order and tax rate:
from bill ( [4000000000000000, 2],
[5.50, 2.86],
0.0765);