-
Notifications
You must be signed in to change notification settings - Fork 96
Expand file tree
/
Copy pathdatabase.sql
More file actions
86 lines (77 loc) · 1.57 KB
/
database.sql
File metadata and controls
86 lines (77 loc) · 1.57 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
-- 1 how many tasks in table
SELECT
count(id) as count_of_rows
FROM
task;
-- 2 how many task have invalid due dates
SELECT
count(id) as not_valid_dates
FROM
task
WHERE
due_date is null;
-- 3 find the task that are marked as done
SELECT
*
FROM
task
INNER JOIN status ON status.id = task.status_id
AND status.name = "Done";
-- 4 Find all the tasks that are not marked as done.
SELECT
*
FROM
task
INNER JOIN status ON status.id = task.status_id
AND status.name != "Done";
-- 5 Get all the tasks, sorted with the most recently created first.
SELECT
*
FROM
task
ORDER BY
created;
-- 6 Get the single most recently created task.
SELECT
*
FROM
task
ORDER BY
created DESC
limit
1;
-- 7 Get the title and due date of all tasks where the title or description contains database.
SELECT
title,
due_date
FROM
task
WHERE
title LIKE "%database%"
OR description like "%database%";
-- 8 Get the title and status (as text) of all tasks.
SELECT
title,
status.name
FROM
task
inner join status on status.id = task.status_id;
-- 9 Get the name of each status, along with a count of how many tasks have that status.
SELECT
COUNT(task.status_id) AS task_have_status,
name
FROM
status
INNER JOIN task on task.status_id = status.id
GROUP BY
status.id;
-- 10 Get the names of all statuses, sorted by the status with most tasks first.
SELECT
status.name
FROM
status
INNER JOIN task on task.status_id = status.id
GROUP BY
status.id
ORDER BY
COUNT(task.status_id) DESC;