2025-01-24 10:36:24 +01:00
|
|
|
{% extends 'set/base/base.sql' %}
|
|
|
|
|
|
|
|
{% block id %}
|
|
|
|
"bricktracker_sets"."id",
|
|
|
|
{% endblock %}
|
|
|
|
|
|
|
|
{% block total_missing %}
|
|
|
|
IFNULL("missing_join"."total", 0) AS "total_missing",
|
|
|
|
{% endblock %}
|
|
|
|
|
|
|
|
{% block total_quantity %}
|
|
|
|
IFNULL("minifigures_join"."total", 0) AS "total_minifigures"
|
|
|
|
{% endblock %}
|
|
|
|
|
|
|
|
{% block join %}
|
|
|
|
{% if statuses %}
|
|
|
|
LEFT JOIN "bricktracker_set_statuses"
|
|
|
|
ON "bricktracker_sets"."id" IS NOT DISTINCT FROM "bricktracker_set_statuses"."bricktracker_set_id"
|
|
|
|
{% endif %}
|
|
|
|
|
|
|
|
-- LEFT JOIN + SELECT to avoid messing the total
|
|
|
|
LEFT JOIN (
|
|
|
|
SELECT
|
|
|
|
"missing"."u_id",
|
|
|
|
SUM("missing"."quantity") AS "total"
|
|
|
|
FROM "missing"
|
|
|
|
{% block where_missing %}{% endblock %}
|
|
|
|
GROUP BY "u_id"
|
|
|
|
) "missing_join"
|
|
|
|
ON "bricktracker_sets"."id" IS NOT DISTINCT FROM "missing_join"."u_id"
|
|
|
|
|
|
|
|
-- LEFT JOIN + SELECT to avoid messing the total
|
|
|
|
LEFT JOIN (
|
|
|
|
SELECT
|
2025-01-27 18:39:35 +01:00
|
|
|
"bricktracker_minifigures"."bricktracker_set_id",
|
|
|
|
SUM("bricktracker_minifigures"."quantity") AS "total"
|
|
|
|
FROM "bricktracker_minifigures"
|
2025-01-24 10:36:24 +01:00
|
|
|
{% block where_minifigures %}{% endblock %}
|
2025-01-27 18:39:35 +01:00
|
|
|
GROUP BY "bricktracker_minifigures"."bricktracker_set_id"
|
2025-01-24 10:36:24 +01:00
|
|
|
) "minifigures_join"
|
2025-01-27 18:39:35 +01:00
|
|
|
ON "bricktracker_sets"."id" IS NOT DISTINCT FROM "minifigures_join"."bricktracker_set_id"
|
2025-01-24 10:36:24 +01:00
|
|
|
{% endblock %}
|