-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocumenter_queries.sql
More file actions
144 lines (121 loc) · 4.32 KB
/
documenter_queries.sql
File metadata and controls
144 lines (121 loc) · 4.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
-- ============================================================
-- SQL Queries to List Documenters
-- ============================================================
-- Run these in Supabase SQL Editor or your database client
-- ============================================================
-- ============================================================
-- Basic Queries
-- ============================================================
-- 1. List all documenters (if documenters table exists)
SELECT * FROM documenters;
-- 2. List documenters with specific columns
SELECT id, name, email, created_at
FROM documenters
ORDER BY name;
-- 3. Count total documenters
SELECT COUNT(*) as total_documenters
FROM documenters;
-- ============================================================
-- If documenter is a column in another table
-- ============================================================
-- 4. List unique documenter names/IDs
SELECT DISTINCT documenter
FROM meetings
WHERE documenter IS NOT NULL
ORDER BY documenter;
-- 5. Count unique documenters
SELECT COUNT(DISTINCT documenter) as total_documenters
FROM meetings
WHERE documenter IS NOT NULL;
-- 6. List all meetings/records with documenter info
SELECT *
FROM meetings
WHERE documenter IS NOT NULL
ORDER BY documenter, date DESC;
-- ============================================================
-- If documenters are linked via foreign keys
-- ============================================================
-- 7. List documenters with their workgroups
SELECT
d.id,
d.name,
d.email,
wg.name as workgroup_name
FROM documenters d
JOIN workgroup_documenters wd ON d.id = wd.documenter_id
JOIN workgroups wg ON wd.workgroup_id = wg.id
ORDER BY wg.name, d.name;
-- 8. List documenters for a specific workgroup
SELECT d.*
FROM documenters d
JOIN workgroup_documenters wd ON d.id = wd.documenter_id
WHERE wd.workgroup_id = 1; -- Replace 1 with your workgroup ID
-- ============================================================
-- If documenters are users with a role
-- ============================================================
-- 9. List users who are documenters
SELECT *
FROM users
WHERE role = 'documenter'
OR role = 'Documenter'
ORDER BY name;
-- 10. List documenters with their activity count
SELECT
documenter,
COUNT(*) as meeting_count,
MIN(date) as first_meeting,
MAX(date) as last_meeting
FROM meetings
WHERE documenter IS NOT NULL
GROUP BY documenter
ORDER BY meeting_count DESC;
-- ============================================================
-- Advanced Queries
-- ============================================================
-- 11. List documenters with their associated workgroups count
SELECT
d.id,
d.name,
COUNT(DISTINCT wd.workgroup_id) as workgroup_count
FROM documenters d
LEFT JOIN workgroup_documenters wd ON d.id = wd.documenter_id
GROUP BY d.id, d.name
ORDER BY workgroup_count DESC, d.name;
-- 12. Find documenters who haven't been assigned to any workgroup
SELECT d.*
FROM documenters d
LEFT JOIN workgroup_documenters wd ON d.id = wd.documenter_id
WHERE wd.documenter_id IS NULL;
-- 13. List documenters with their recent meetings
SELECT
d.name as documenter,
m.title as meeting_title,
m.date,
wg.name as workgroup
FROM documenters d
JOIN meetings m ON m.documenter_id = d.id
JOIN workgroups wg ON m.workgroup_id = wg.id
WHERE m.date >= CURRENT_DATE - INTERVAL '30 days'
ORDER BY m.date DESC, d.name;
-- ============================================================
-- Search/Filter Queries
-- ============================================================
-- 14. Search documenters by name
SELECT *
FROM documenters
WHERE name ILIKE '%john%' -- Replace 'john' with search term
ORDER BY name;
-- 15. List documenters created in the last month
SELECT *
FROM documenters
WHERE created_at >= CURRENT_DATE - INTERVAL '30 days'
ORDER BY created_at DESC;
-- ============================================================
-- Notes:
-- ============================================================
-- • Adjust table/column names based on your actual schema
-- • Replace placeholder IDs (like workgroup_id = 1) with actual values
-- • Use ILIKE for case-insensitive text search in PostgreSQL
-- • Add LIMIT clauses if you have many results:
-- SELECT * FROM documenters LIMIT 100;
-- ============================================================