GitHub Action
commited on
Commit
·
840670d
1
Parent(s):
5151c3c
Sync from GitHub with Git LFS
Browse files
agents/tools/db_structure.sql
CHANGED
@@ -480,21 +480,82 @@ GROUP BY ss.id;
|
|
480 |
|
481 |
DROP VIEW IF EXISTS tag_usage;
|
482 |
CREATE VIEW tag_usage AS
|
483 |
-
|
|
|
484 |
SELECT
|
485 |
-
id AS
|
|
|
486 |
TRIM(value) AS tag,
|
487 |
timestamp AS entry_time
|
488 |
FROM diary_entries,
|
489 |
-
json_each('[' || REPLACE(tags, ',', '","') || ']')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
490 |
)
|
|
|
|
|
491 |
SELECT
|
492 |
tag,
|
493 |
-
COUNT(
|
494 |
MIN(entry_time) AS first_used,
|
495 |
-
MAX(entry_time) AS last_used
|
496 |
-
|
|
|
|
|
497 |
GROUP BY tag
|
498 |
ORDER BY usage_count DESC;
|
499 |
-
|
500 |
-
|
|
|
480 |
|
481 |
DROP VIEW IF EXISTS tag_usage;
|
482 |
CREATE VIEW tag_usage AS
|
483 |
+
-- Дневник
|
484 |
+
WITH diary_split AS (
|
485 |
SELECT
|
486 |
+
id AS source_id,
|
487 |
+
'diary_entries' AS source_table,
|
488 |
TRIM(value) AS tag,
|
489 |
timestamp AS entry_time
|
490 |
FROM diary_entries,
|
491 |
+
json_each('[' || REPLACE(IFNULL(tags,''), ',', '","') || ']')
|
492 |
+
),
|
493 |
+
|
494 |
+
-- Концепты
|
495 |
+
concepts_split AS (
|
496 |
+
SELECT
|
497 |
+
id AS source_id,
|
498 |
+
'concepts' AS source_table,
|
499 |
+
TRIM(value) AS tag,
|
500 |
+
timestamp AS entry_time
|
501 |
+
FROM concepts,
|
502 |
+
json_each('[' || REPLACE(IFNULL(tags,''), ',', '","') || ']')
|
503 |
+
),
|
504 |
+
|
505 |
+
-- Семантические связи
|
506 |
+
links_split AS (
|
507 |
+
SELECT
|
508 |
+
id AS source_id,
|
509 |
+
'links' AS source_table,
|
510 |
+
TRIM(value) AS tag,
|
511 |
+
timestamp AS entry_time
|
512 |
+
FROM links,
|
513 |
+
json_each('[' || REPLACE(IFNULL(tags,''), ',', '","') || ']')
|
514 |
+
),
|
515 |
+
|
516 |
+
-- Цели
|
517 |
+
goals_split AS (
|
518 |
+
SELECT
|
519 |
+
id AS source_id,
|
520 |
+
'goals' AS source_table,
|
521 |
+
TRIM(value) AS tag,
|
522 |
+
timestamp AS entry_time
|
523 |
+
FROM goals,
|
524 |
+
json_each('[' || REPLACE(IFNULL(tags,''), ',', '","') || ']')
|
525 |
+
),
|
526 |
+
|
527 |
+
-- Задачи
|
528 |
+
tasks_split AS (
|
529 |
+
SELECT
|
530 |
+
id AS source_id,
|
531 |
+
'tasks' AS source_table,
|
532 |
+
TRIM(value) AS tag,
|
533 |
+
timestamp AS entry_time
|
534 |
+
FROM tasks,
|
535 |
+
json_each('[' || REPLACE(IFNULL(tags,''), ',', '","') || ']')
|
536 |
+
),
|
537 |
+
|
538 |
+
-- Объединение
|
539 |
+
all_tags AS (
|
540 |
+
SELECT * FROM diary_split
|
541 |
+
UNION ALL
|
542 |
+
SELECT * FROM concepts_split
|
543 |
+
UNION ALL
|
544 |
+
SELECT * FROM links_split
|
545 |
+
UNION ALL
|
546 |
+
SELECT * FROM goals_split
|
547 |
+
UNION ALL
|
548 |
+
SELECT * FROM tasks_split
|
549 |
)
|
550 |
+
|
551 |
+
-- Финальная выборка
|
552 |
SELECT
|
553 |
tag,
|
554 |
+
COUNT(source_id) AS usage_count,
|
555 |
MIN(entry_time) AS first_used,
|
556 |
+
MAX(entry_time) AS last_used,
|
557 |
+
GROUP_CONCAT(DISTINCT source_table) AS sources
|
558 |
+
FROM all_tags
|
559 |
+
WHERE tag IS NOT NULL AND tag <> ''
|
560 |
GROUP BY tag
|
561 |
ORDER BY usage_count DESC;
|
|
|
|