This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const trappedRainwater = (arr) => { | |
| let totalWater = 0; | |
| let leftMax = arr[0]; | |
| let rightMax = arr[arr.length - 1]; | |
| let leftIndex = 1; // Note that I do not take in consideration the very first element and the very last element of array as they will never catch any water | |
| let rightIndex = arr.length - 2; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- Table creation | |
| CREATE TABLE store( | |
| order_id integer, | |
| order_date date, | |
| customer_id integer, | |
| customer_phone varchar(50), | |
| customer_email text, | |
| item_1_id integer, | |
| item_1_name varchar(100), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- Table Creation Process | |
| CREATE TABLE books ( | |
| book_id integer, | |
| title varchar(250), | |
| author varchar(250), | |
| original_language varchar(100), | |
| first_published integer, | |
| sales_in_millions numeric, | |
| price numeric |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- The parts table is the central table in our database, it stores all the information about the individual parts in our storeroom. Let’s make sure that we have some basic checks in place to ensure data integrity. Alter the code column so that each value inserted into this field is unique and not empty. | |
| ALTER TABLE parts | |
| ADD UNIQUE(code); | |
| ALTER TABLE parts | |
| ALTER COLUMN code SET NOT NULL; | |
| -- The parts table is missing values in the description column. Alter the table so that all rows have a value for description. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| Creating Tables and Relationships => | |
| ONE TO ONE => restaurant and address | |
| ONE TO MANY => restaurant and review | |
| MANY TO MANY => category and dish => categories_dishes | |
| */ | |
| CREATE TABLE restaurant( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --Let’s practice what we learned about joins by combining rows from different tables.. | |
| --Suppose you are a Data Analyst at Lyft, a ride-sharing platform. For a project, you were given three tables: | |
| --trips: trips information | |
| --riders: user data | |
| --cars: autonomous cars | |
| -- trips table |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- Unfortunately the Dataset was not made public and could be used only within Codacedemy project | |
| --Hacker News is a popular website run by Y Combinator. It’s widely known by people in the tech industry as a community site for sharing --news, showing off projects, asking questions, among other things. | |
| --In this project, you will be working with a table named hacker_news that contains stories from Hacker News since its launch in 2007. --It has the following columns: | |
| --title: the title of the story | |
| --user: the user who submitted the story | |
| --score: the score of the story |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- Table creation | |
| CREATE TABLE startups( | |
| name TEXT, | |
| location TEXT, | |
| category TEXT, | |
| employees INTEGER, | |
| raised INTEGER, | |
| valuation INTEGER, | |
| founded INTEGER, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- First, let`s create a Table | |
| CREATE TABLE nomnom ( | |
| name TEXT, | |
| neighborhood TEXT, | |
| cuisine TEXT, | |
| review REAL, | |
| price TEXT, | |
| health TEXT | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| CREATE TABLE films ( | |
| name TEXT, | |
| release_year INTEGER | |
| ); | |
| INSERT INTO films (name, release_year) | |
| VALUES ('The Matrix', 1999); | |
| INSERT INTO films (name, release_year) | |
| VALUES ('Monsters, Inc.', 2001); |
NewerOlder