|
@@ -0,0 +1,53 @@
|
|
|
|
+SELECT
|
|
|
|
+ 'dynamic' as component,
|
|
|
|
+ sqlpage.run_sql('cookie.sql') AS properties
|
|
|
|
+;
|
|
|
|
+
|
|
|
|
+SELECT
|
|
|
|
+ 'dynamic' as component,
|
|
|
|
+ sqlpage.run_sql('nav.sql') AS properties
|
|
|
|
+;
|
|
|
|
+
|
|
|
|
+SELECT
|
|
|
|
+ 'table' AS component,
|
|
|
|
+ TRUE AS search,
|
|
|
|
+ TRUE AS striped_rows,
|
|
|
|
+ TRUE AS small,
|
|
|
|
+ 'Notice' AS markdown
|
|
|
|
+;
|
|
|
|
+
|
|
|
|
+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
|
|
|
|
+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 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
|
|
|
|
+ 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 ROLLUP (g.name, c.name, p.name)
|
|
|
|
+ORDER BY product, category, "group") q
|
|
|
|
+WHERE q.category IS NULL
|
|
|
|
+);
|
|
|
|
+SELECT * FROM sqlpage_tags;
|
|
|
|
+
|
|
|
|
+SELECT
|
|
|
|
+ '# No Data' AS "Notice"
|
|
|
|
+WHERE NOT EXISTS(SELECT * FROM sqlpage_tags LIMIT 1);
|