GitHub Action commited on
Commit
ea93927
·
1 Parent(s): 1164284

Sync from GitHub with Git LFS

Browse files
Files changed (1) hide show
  1. agents/tools/db_structure.sql +25 -0
agents/tools/db_structure.sql CHANGED
@@ -434,3 +434,28 @@ FROM stagnation_strategies ss
434
  LEFT JOIN ratings r
435
  ON r.target_type = 'stagnation_strategy' AND r.target_id = ss.id
436
  GROUP BY ss.id;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
434
  LEFT JOIN ratings r
435
  ON r.target_type = 'stagnation_strategy' AND r.target_id = ss.id
436
  GROUP BY ss.id;
437
+
438
+ -- ============================================
439
+ -- Унифицированное VIEW для тегов
440
+ -- ============================================
441
+
442
+ DROP VIEW IF EXISTS tag_usage;
443
+ CREATE VIEW tag_usage AS
444
+ WITH split_tags AS (
445
+ SELECT
446
+ id AS entry_id,
447
+ TRIM(value) AS tag,
448
+ timestamp AS entry_time
449
+ FROM diary_entries,
450
+ json_each('[' || REPLACE(tags, ',', '","') || ']')
451
+ )
452
+ SELECT
453
+ tag,
454
+ COUNT(entry_id) AS usage_count,
455
+ MIN(entry_time) AS first_used,
456
+ MAX(entry_time) AS last_used
457
+ FROM split_tags
458
+ GROUP BY tag
459
+ ORDER BY usage_count DESC;
460
+
461
+