Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Binary file added QueriesOuput/Day2/Screenshot (271).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added QueriesOuput/Day2/query1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added QueriesOuput/Day2/query2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added QueriesOuput/Day2/query3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added QueriesOuput/Day2/query4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added QueriesOuput/Day2/query5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added QueriesOuput/Day2/query6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added QueriesOuput/Day2/query7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added QueriesOuput/Day2/query8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added QueriesOuput/Day2/query9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 23 additions & 8 deletions data.sql
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
SET datestyle = dmy;

INSERT INTO animals(id, name, date_of_birth, escape_attempts, neutered, weight_kg)
VALUES(1, 'Agumon','02/03/2020',0,true,10.23);
INSERT INTO animals(id, name, date_of_birth, escape_attempts, neutered, weight_kg)
VALUES(2, 'Gabumon','15/11/2018',2,true,8.0);
INSERT INTO animals(id, name, date_of_birth, escape_attempts, neutered, weight_kg)
VALUES(3, 'Pikachu','07/01/2021',1,false,15.04);
INSERT INTO animals(id, name, date_of_birth, escape_attempts, neutered, weight_kg)
VALUES(4, 'Devimon','12/05/2017',5,true,11.0);
INSERT INTO animals(name, date_of_birth, escape_attempts, neutered, weight_kg)
VALUES('Agumon','02/03/2020',0,true,10.23);

INSERT INTO animals(name, date_of_birth, escape_attempts, neutered, weight_kg)
VALUES('Gabumon','15/11/2018',2,true,8.0);
INSERT INTO animals(name, date_of_birth, escape_attempts, neutered, weight_kg)
VALUES('Pikachu','07/01/2021',1,false,15.04);
INSERT INTO animals(name, date_of_birth, escape_attempts, neutered, weight_kg)
VALUES('Devimon','12/05/2017',5,true,11.0);
INSERT INTO animals(name, date_of_birth, escape_attempts, neutered, weight_kg)
VALUES('Charmander','08/02/2020',0,false,-11.0);
INSERT INTO animals(name, date_of_birth, escape_attempts, neutered, weight_kg)
VALUES('Plantmon','15/11/2021',2,true,-5.7);
INSERT INTO animals(name, date_of_birth, escape_attempts, neutered, weight_kg)
VALUES('Squirtle','02/04/1993',3,false,-12.13);
INSERT INTO animals(name, date_of_birth, escape_attempts, neutered, weight_kg)
VALUES('Angemon','12/06/2005',1,true,-45.0);
INSERT INTO animals(name, date_of_birth, escape_attempts, neutered, weight_kg)
VALUES('Boarmon','07/06/2005',7,true,20.4);
INSERT INTO animals(name, date_of_birth, escape_attempts, neutered, weight_kg)
VALUES('Blossom','13/10/1998',3,true,17.0);
INSERT INTO animals(name, date_of_birth, escape_attempts, neutered, weight_kg)
VALUES('Ditto','14/05/2022',4,true,22.0);
42 changes: 41 additions & 1 deletion queries.sql
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,44 @@ SELECT * FROM animals
WHERE name != 'Gabumon';

SELECT * FROM animals
WHERE weight_kg >= 10.4 AND weight_kg <= 17.3
WHERE weight_kg >= 10.4 AND weight_kg <= 17.3

-- queries to perform transaction

BEGIN;
UPDATE animals SET species = 'unspecified';
ROLLBACK;

BEGIN;
UPDATE animals SET species = 'digimon' WHERE name like '%mon';
UPDATE animals SET species = 'pokemon'WHERE species is null;
COMMIT;

BEGIN;
DELETE FROM animals;
ROLLBACK;

BEGIN;
DELETE FROM animals WHERE date_of_birth > '01/07/2022';
SAVEPOINT savepoint_1;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

  • This transaction should delete all animals born after Jan 1st, 2022 (01/01/2022) and not the 1st of July 2022(01/07/2022). Kindly correct the error so that the correct number of animals can be deleted. Please, don't forget to update the screenshot attached to your pull request summary 😎 💻

UPDATE animals SET weight_kg = (weight_kg * -1);
ROLLBACK TO savepoint_1;
UPDATE animals SET weight_kg = (weight_kg * - 1) WHERE weight_kg < 0;
COMMIT;

-- queries to perform aggregate functions

SELECT COUNT(*) FROM animals;

Comment on lines +56 to +58
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

  • The total number of animals should be 10 and not 11. By the time you update the transactions that should delete all animals born after 01/01/2022, you would have 10 as the total number of animals. Kindly update the screenshot for this query after the transaction. 👍 💻

SELECT COUNT(*) FROM animals WHERE escape_attempts = 0;

SELECT AVG(weight_kg) FROM animals

Comment on lines +60 to +62
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

  • The average weight of animals should be 15.55 and not 16.136363 . By the time you update the transactions that should delete all animals born after 01/01/2022, you would have 15.55 as the average weight of animals. Kindly update the screenshot for this query after the transaction. 👍 💻

SELECT name FROM animals
ORDER BY escape_attempts DESC LIMIT 1;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

  • This query should return a result that shows who attempts to escape the most classified by the neutered character of the animals. Currently, you have the name of the animals who attempted to escape the most but it should be an analysis of animals based on the neutered character. In the end, your result should look familiar to this:

image

Please remember to update the screenshot when you are done. 👍


SELECT MIN(weight_kg), MAX(weight_kg) FROM animals GROUP BY(species);

Comment on lines +66 to +68
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

  • The maximum weight of pokemon animals should be 17 and not 22. By the time you update the transactions that should delete all animals born after 01/01/2022, you would have 17 as the maximum weight of pokemon animals. Kindly update the screenshot for this query after the transaction. 👍 💻

SELECT ROUND(AVG(escape_attempts),2) AS average FROM animals
WHERE EXTRACT(YEAR FROM date_of_birth) BETWEEN '1990' AND '2000'
GROUP BY(species) ORDER BY average;
7 changes: 5 additions & 2 deletions schema.sql
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
/* Database schema to keep the structure of entire database. */
CREATE TABLE animals(
id INTEGER NOT NULL PRIMARY KEY,
id SERIAL NOT NULL PRIMARY KEY,
name VARCHAR(255) NOT NULL,
date_of_birth DATE NOT NULL,
escape_attempts integer NOT NULL,
neutered BOOLEAN NOT NULL,
weight_kg FLOAT NOT NULL
);
);

ALTER TABLE animals
ADD COLUMN species VARCHAR(255);