Commit
·
f98fee6
1
Parent(s):
20ece27
Update README.md
Browse files
README.md
CHANGED
@@ -94,41 +94,71 @@ Here is the SQL query that answers the question: `{natural language question}`
|
|
94 |
### **Example Schemas**
|
95 |
|
96 |
```sql
|
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 |
-
**Question**: **
|
123 |
```sql
|
124 |
-
SELECT
|
|
|
|
|
|
|
|
|
125 |
```
|
126 |
-
**Question**: **
|
127 |
```sql
|
128 |
-
SELECT
|
|
|
|
|
|
|
|
|
|
|
|
|
129 |
```
|
130 |
|
131 |
-
**Question**: **What is the
|
132 |
```sql
|
133 |
-
SELECT
|
|
|
|
|
|
|
134 |
```
|
|
|
94 |
### **Example Schemas**
|
95 |
|
96 |
```sql
|
97 |
+
CREATE TABLE users (
|
98 |
+
user_id SERIAL PRIMARY KEY,
|
99 |
+
username VARCHAR(50) NOT NULL,
|
100 |
+
email VARCHAR(100) NOT NULL,
|
101 |
+
password_hash TEXT NOT NULL,
|
102 |
+
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
|
103 |
+
);
|
104 |
+
|
105 |
+
CREATE TABLE projects (
|
106 |
+
project_id SERIAL PRIMARY KEY,
|
107 |
+
project_name VARCHAR(100) NOT NULL,
|
108 |
+
description TEXT,
|
109 |
+
start_date DATE,
|
110 |
+
end_date DATE,
|
111 |
+
owner_id INTEGER REFERENCES users(user_id)
|
112 |
+
);
|
113 |
+
|
114 |
+
CREATE TABLE tasks (
|
115 |
+
task_id SERIAL PRIMARY KEY,
|
116 |
+
task_name VARCHAR(100) NOT NULL,
|
117 |
+
description TEXT,
|
118 |
+
due_date DATE,
|
119 |
+
status VARCHAR(50),
|
120 |
+
project_id INTEGER REFERENCES projects(project_id)
|
121 |
+
);
|
122 |
+
|
123 |
+
CREATE TABLE taskassignments (
|
124 |
+
assignment_id SERIAL PRIMARY KEY,
|
125 |
+
task_id INTEGER REFERENCES tasks(task_id),
|
126 |
+
user_id INTEGER REFERENCES users(user_id),
|
127 |
+
assigned_date DATE NOT NULL DEFAULT CURRENT_TIMESTAMP
|
128 |
+
);
|
129 |
+
|
130 |
+
CREATE TABLE comments (
|
131 |
+
comment_id SERIAL PRIMARY KEY,
|
132 |
+
content TEXT NOT NULL,
|
133 |
+
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
134 |
+
task_id INTEGER REFERENCES tasks(task_id),
|
135 |
+
user_id INTEGER REFERENCES users(user_id)
|
136 |
+
);
|
137 |
```
|
138 |
|
139 |
+
**Question**: **Show me the day with the most users joining**
|
140 |
```sql
|
141 |
+
SELECT created_at::DATE AS day, COUNT(*) AS user_count
|
142 |
+
FROM users
|
143 |
+
GROUP BY day
|
144 |
+
ORDER BY user_count DESC
|
145 |
+
LIMIT 1;
|
146 |
```
|
147 |
+
**Question**: **Show me the project that has a task with the most comments**
|
148 |
```sql
|
149 |
+
SELECT p.project_name, t.task_name, COUNT(c.comment_id) AS comment_count
|
150 |
+
FROM projects p
|
151 |
+
JOIN tasks t ON p.project_id = t.project_id
|
152 |
+
JOIN comments c ON t.task_id = c.task_id
|
153 |
+
GROUP BY p.project_name, t.task_name
|
154 |
+
ORDER BY comment_count DESC
|
155 |
+
LIMIT 1;
|
156 |
```
|
157 |
|
158 |
+
**Question**: **What is the ratio of users with gmail addresses vs without?**
|
159 |
```sql
|
160 |
+
SELECT
|
161 |
+
SUM(CASE WHEN email ILIKE '%@gmail.com%' THEN 1 ELSE 0 END)::FLOAT / NULLIF(SUM(CASE WHEN email NOT ILIKE '%@gmail.com%' THEN 1 ELSE 0 END), 0) AS gmail_ratio
|
162 |
+
FROM
|
163 |
+
users;
|
164 |
```
|