2025-01-17 11:03:00 +01:00
|
|
|
SELECT
|
2025-01-20 19:39:12 +01:00
|
|
|
"sets"."set_num",
|
|
|
|
"sets"."name",
|
|
|
|
"sets"."year",
|
|
|
|
"sets"."theme_id",
|
|
|
|
"sets"."num_parts",
|
|
|
|
"sets"."set_img_url",
|
|
|
|
"sets"."set_url",
|
|
|
|
"sets"."last_modified_dt",
|
|
|
|
"sets"."mini_col",
|
|
|
|
"sets"."set_check",
|
|
|
|
"sets"."set_col",
|
|
|
|
"sets"."u_id",
|
2025-01-17 11:03:00 +01:00
|
|
|
{% block number %}
|
2025-01-20 19:39:12 +01:00
|
|
|
CAST(SUBSTR("sets"."set_num", 1, INSTR("sets"."set_num", '-') - 1) AS INTEGER) AS "set_number",
|
2025-01-21 11:27:50 +01:00
|
|
|
CAST(SUBSTR("sets"."set_num", INSTR("sets"."set_num", '-') + 1) AS INTEGER) AS "set_version",
|
2025-01-17 11:03:00 +01:00
|
|
|
{% endblock %}
|
2025-01-20 19:39:12 +01:00
|
|
|
IFNULL("missing_join"."total", 0) AS "total_missing",
|
|
|
|
IFNULL("minifigures_join"."total", 0) AS "total_minifigures"
|
2025-01-17 11:03:00 +01:00
|
|
|
FROM sets
|
|
|
|
|
|
|
|
-- LEFT JOIN + SELECT to avoid messing the total
|
|
|
|
LEFT JOIN (
|
|
|
|
SELECT
|
2025-01-20 19:39:12 +01:00
|
|
|
"missing"."u_id",
|
|
|
|
SUM("missing"."quantity") AS "total"
|
|
|
|
FROM "missing"
|
2025-01-17 11:03:00 +01:00
|
|
|
{% block where_missing %}{% endblock %}
|
2025-01-20 19:39:12 +01:00
|
|
|
GROUP BY "u_id"
|
|
|
|
) "missing_join"
|
|
|
|
ON "sets"."u_id" IS NOT DISTINCT FROM "missing_join"."u_id"
|
2025-01-17 11:03:00 +01:00
|
|
|
|
|
|
|
-- LEFT JOIN + SELECT to avoid messing the total
|
|
|
|
LEFT JOIN (
|
|
|
|
SELECT
|
2025-01-20 19:39:12 +01:00
|
|
|
"minifigures"."u_id",
|
|
|
|
SUM("minifigures"."quantity") AS "total"
|
|
|
|
FROM "minifigures"
|
2025-01-17 11:03:00 +01:00
|
|
|
{% block where_minifigures %}{% endblock %}
|
2025-01-20 19:39:12 +01:00
|
|
|
GROUP BY "u_id"
|
|
|
|
) "minifigures_join"
|
|
|
|
ON "sets"."u_id" IS NOT DISTINCT FROM "minifigures_join"."u_id"
|
2025-01-17 11:03:00 +01:00
|
|
|
|
|
|
|
{% block where %}{% endblock %}
|
|
|
|
|
|
|
|
{% if order %}
|
|
|
|
ORDER BY {{ order }}
|
|
|
|
{% endif %}
|
|
|
|
|
|
|
|
{% if limit %}
|
|
|
|
LIMIT {{ limit }}
|
|
|
|
{% endif %}
|