-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
database week1/jianxin #148
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
-- Find out how many tasks are in the task table | ||
SELECT count(id) FROM task; | ||
|
||
-- Find out how many tasks in the task table do not have a valid due date | ||
SELECT count(id) FROM task | ||
WHERE due_date is NULL; | ||
|
||
-- Find all the tasks that are marked as done | ||
SELECT * FROM task | ||
WHERE status_id IN (SELECT id FROM status WHERE name LIKE "%done%"); | ||
|
||
-- Find all the tasks that are not marked as done | ||
SELECT * FROM task | ||
WHERE status_id NOT IN (SELECT id FROM status WHERE name LIKE "%done%"); | ||
|
||
-- Get all the tasks, sorted with the most recently created first | ||
SELECT * FROM task | ||
ORDER BY created DESC; | ||
|
||
-- Get the single most recently created task | ||
SELECT * FROM task | ||
ORDER BY created DESC | ||
LIMIT 1; | ||
|
||
-- 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%"; | ||
|
||
-- Get the title and status (as text) of all tasks | ||
SELECT task.title AS task_title, status.name AS task_status | ||
FROM task | ||
LEFT JOIN status on task.status_id = status.id; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The column This doesn't block the review either, but I suggest that you use |
||
|
||
-- Get the name of each status, along with a count of how many tasks have that status | ||
SELECT status.name AS task_status, count(task.title) AS task_count | ||
FROM task | ||
LEFT JOIN status on task.status_id = status.id | ||
GROUP BY task_status; | ||
|
||
-- Get the names of all statuses, sorted by the status with most tasks first | ||
SELECT status.name AS task_status, count(task.title) AS task_count | ||
FROM task | ||
LEFT JOIN status on task.status_id = status.id | ||
GROUP BY task_status | ||
ORDER BY task_count DESC; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not block the review because your query works, but I still suggest you follow this advice to get more clear and meaningful code.
You use
IN
when there is a list of possible values. Although it works in this case, there is only one status for "Done", so you could doSELECT * FROM task WHERE status_id = (...)
and this statement would be a bit more clear.Similarly, in the subquery you are searching for statuses whose name contain
done
. There is only one status for "Done", so you could doSELECT id FROM status WHERe name = 'Done'
, which again is a bit more clear.