|
@@ -3,6 +3,11 @@ SELECT
|
|
|
sqlpage.run_sql('cookie.sql') AS properties
|
|
|
;
|
|
|
|
|
|
+SELECT 'shell' AS component,
|
|
|
+ 'dark' AS theme,
|
|
|
+ 'Tags' AS title
|
|
|
+;
|
|
|
+
|
|
|
SELECT
|
|
|
'dynamic' as component,
|
|
|
sqlpage.run_sql('nav.sql') AS properties
|
|
@@ -19,22 +24,37 @@ SELECT
|
|
|
DROP TABLE IF EXISTS sqlpage_tags;
|
|
|
CREATE TEMPORARY TABLE IF NOT EXISTS sqlpage_tags AS (
|
|
|
SELECT * FROM (SELECT count(DISTINCT txn.id) AS "Uses", tg.name AS "Name"
|
|
|
- FROM tags tg
|
|
|
- JOIN tags_map tm ON tg.id = tm.tag_id
|
|
|
- JOIN transactions txn ON txn.id = tm.transaction_id
|
|
|
- WHERE {where}
|
|
|
- GROUP BY tg.name
|
|
|
- ORDER BY 1 DESC, 2) q
|
|
|
+FROM tags tg
|
|
|
+JOIN tags_map tm ON tg.id = tm.tag_id
|
|
|
+JOIN transactions txn ON txn.id = tm.transaction_id
|
|
|
+JOIN products p ON p.id = txn.product_id
|
|
|
+JOIN categories c ON p.category_id = c.id
|
|
|
+JOIN groups g ON c.group_id = g.id
|
|
|
+JOIN sqlpage_options op ON op.type = 'product' AND p.name = op.name
|
|
|
+JOIN sqlpage_options oc ON oc.type = 'category' AND c.name = oc.name
|
|
|
+JOIN sqlpage_options og ON og.type = 'group' AND g.name = og.name
|
|
|
+WHERE
|
|
|
+ COALESCE(op.selected, oc.selected, og.selected, TRUE)
|
|
|
+AND
|
|
|
+ op.session = sqlpage.cookie('session')
|
|
|
+AND
|
|
|
+ oc.session = sqlpage.cookie('session')
|
|
|
+AND
|
|
|
+ og.session = sqlpage.cookie('session')
|
|
|
+GROUP BY tg.name
|
|
|
+ORDER BY 1 DESC, 2) q
|
|
|
UNION ALL
|
|
|
SELECT count(DISTINCT txn.id) AS "Uses", count(DISTINCT tg.name)||'' AS "Name"
|
|
|
FROM tags tg
|
|
|
JOIN tags_map tm ON tg.id = tm.tag_id
|
|
|
JOIN transactions txn ON txn.id = tm.transaction_id
|
|
|
+JOIN products p ON p.id = txn.product_id
|
|
|
+JOIN categories c ON p.category_id = c.id
|
|
|
+JOIN groups g ON c.group_id = g.id
|
|
|
JOIN sqlpage_options op ON op.type = 'product' AND p.name = op.name
|
|
|
JOIN sqlpage_options oc ON oc.type = 'category' AND c.name = oc.name
|
|
|
JOIN sqlpage_options og ON og.type = 'group' AND g.name = og.name
|
|
|
-WHERE COALESCE(op.selected, oc.selected, og.selected, TRUE)
|
|
|
-AND
|
|
|
+WHERE
|
|
|
COALESCE(op.selected, oc.selected, og.selected, TRUE)
|
|
|
AND
|
|
|
op.session = sqlpage.cookie('session')
|
|
@@ -42,9 +62,6 @@ AND
|
|
|
oc.session = sqlpage.cookie('session')
|
|
|
AND
|
|
|
og.session = sqlpage.cookie('session')
|
|
|
-GROUP BY ROLLUP (g.name, c.name, p.name)
|
|
|
-ORDER BY product, category, "group") q
|
|
|
-WHERE q.category IS NULL
|
|
|
);
|
|
|
SELECT * FROM sqlpage_tags;
|
|
|
|