Skip to content
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

Databases week1/parisa #149

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions class30-homework
Submodule class30-homework added at e774a9
46 changes: 46 additions & 0 deletions databases/week1/database.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
USE hyf_lesson1

SELECT COUNT(*) AS total_tasks FROM task;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job on using an alias with the AS keryword. 😉

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot, I appreciate your time and suggestions.


SELECT COUNT(*) AS invalid_due_dates
FROM task
WHERE due_date IS NULL

SELECT *
FROM task
WHERE status_id = (SELECT id FROM status WHERE name = 'Done');

SELECT *
FROM task
WHERE status_id != (SELECT id FROM status WHERE name = 'Done');
Comment on lines +9 to +15
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work on using a subquery!


SELECT *
FROM task
ORDER BY created DESC;

SELECT *
FROM task
ORDER BY created DESC
LIMIT 1;

SELECT title, due_date
FROM task
WHERE title LIKE '%database%'
OR description LIKE '%database%';

SELECT task.title, status.name AS status
FROM task
JOIN status ON task.status_id = status.id;

SELECT status.name, COUNT(task.id) AS task_count
FROM status
LEFT JOIN task ON status.id = task.status_id
GROUP BY status.name;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing! You had the attention to detail to use LEFT JOIN here, instead of a simple JOIN. This is the correct way to do it, since this means that if a status does not have a task that would be associated with it, the status would still show up in the result with a task_count of 0. With a simple JOIN this would not happen. Well done!!! 🤩


SELECT status.name, COUNT(task.id) AS task_count
FROM status
LEFT JOIN task ON status.id = task.status_id
GROUP BY status.name
ORDER BY task_count DESC;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same applies here, use a LEFT JOIN here as well.