BrickTracker/bricktracker/sql/minifigure/list/all.sql

35 lines
853 B
MySQL
Raw Normal View History

2025-01-17 11:03:00 +01:00
{% extends 'minifigure/base/select.sql' %}
{% block total_missing %}
SUM(IFNULL("missing_join"."total", 0)) AS "total_missing",
2025-01-17 11:03:00 +01:00
{% endblock %}
{% block "total_quantity" %}
SUM(IFNULL("minifigures"."quantity", 0)) AS "total_quantity",
2025-01-17 11:03:00 +01:00
{% endblock %}
{% block total_sets %}
COUNT("minifigures"."set_num") AS "total_sets"
2025-01-17 11:03:00 +01:00
{% endblock %}
{% block join %}
-- LEFT JOIN + SELECT to avoid messing the total
LEFT JOIN (
SELECT
"missing"."set_num",
"missing"."u_id",
SUM("missing"."quantity") AS total
FROM "missing"
2025-01-17 11:03:00 +01:00
GROUP BY
"missing"."set_num",
"missing"."u_id"
2025-01-17 11:03:00 +01:00
) missing_join
ON "minifigures"."u_id" IS NOT DISTINCT FROM "missing_join"."u_id"
AND "minifigures"."fig_num" IS NOT DISTINCT FROM "missing_join"."set_num"
2025-01-17 11:03:00 +01:00
{% endblock %}
{% block group %}
GROUP BY
"minifigures"."fig_num"
2025-01-17 11:03:00 +01:00
{% endblock %}