SELECT 'card' AS component
, 'Cost by Quantity' AS title
, 2 AS columns
;

SELECT 'trend/Quantity.sql?unit='||$unit_mass||'&log_scale='||$log_scale||'&_sqlpage_embed' AS embed
, '' AS footer
WHERE EXISTS (SELECT 1 FROM sqlpage_txn WHERE unit = $unit_mass LIMIT 1)
;

SELECT 'trend/Quantity.sql?unit='||$unit_volume||'&log_scale='||$log_scale||'&_sqlpage_embed' AS embed
, '' AS footer
WHERE EXISTS (SELECT 1 FROM sqlpage_txn WHERE unit = $unit_volume LIMIT 1)
;

SET unit_count_chart = (SELECT v#>>'{}' FROM json_array_elements($unit_count::json) j(v) LIMIT 1);
SELECT 'trend/Quantity.sql?unit='||$unit_count_chart||'&log_scale='||$log_scale||'&_sqlpage_embed' AS embed
, '' AS footer
WHERE EXISTS (SELECT 1 FROM sqlpage_txn WHERE unit = $unit_count_chart LIMIT 1)
AND (SELECT count(DISTINCT v#>>'{}') FROM json_array_elements($unit_count::json) j(v)) == 1
;
