{ "id": "freeCodeCamp/learn-sql-by-building-a-student-database-part-2:v1.0.0", "version": "2.0.0", "summary": { "title": "Learn SQL by Building a Student Database: Part 2", "description": "> Welcome to Part 2 of the Build a Student Database Lessons!" }, "config": { "setup": { "commands": [ "./.freeCodeCamp/reset.sh", "cd .freeCodeCamp && npm install" ], "commits": [ "8c97b76e08f0815374a74ce6d8cfec2add16e489" ] }, "testRunner": { "command": "npm run programmatic-test", "args": { "tap": "--reporter=mocha-tap-reporter" }, "directory": ".freeCodeCamp" }, "repo": { "uri": "https://github.com/freeCodeCamp/learn-sql-by-building-a-student-database-part-2", "branch": "v2.0.0" }, "continue": { "commands": [ "./.freeCodeCamp/reset.sh" ] }, "reset": { "commands": [ "./.freeCodeCamp/reset.sh" ] }, "dependencies": [ { "name": "node", "version": ">=10" } ], "webhook": { "url": "https://api.freecodecamp.org/coderoad-challenge-completed", "events": { "init": false, "reset": false, "step_complete": false, "level_complete": false, "tutorial_complete": true } } }, "levels": [ { "id": "10", "title": "Start the Terminal", "summary": "", "content": "", "steps": [ { "id": "10.1", "setup": { "watchers": [ "../.bash_history" ], "commits": [ "d58fba7fe4cfc8c3925b92610674e40e9deb4456" ] }, "content": "**The first thing you need to do is start the terminal.** Do that by clicking the \"hamburger\" menu at the top left of the screen, going to the \"terminal\" section, and clicking \"new terminal\". Once you open a new one, type `echo hello SQL` into the terminal and press enter.", "hints": [ "Capitalization matters", "If the tests don't run automatically, try typing `exit` into the terminal and redoing the instructions" ] } ] }, { "id": "20", "title": "psql login", "summary": "", "content": "", "steps": [ { "id": "20.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "87aed7f9c4db049274e851969ac0b0149a341a56" ] }, "content": "In Part 1 of this tutorial, you created a `students` database and then a script to insert information about your computer science students into it. Log into the psql interactive terminal with `psql --username=freecodecamp --dbname=postgres` to see if it's here.", "hints": [ "Type `psql --username=freecodecamp --dbname=postgres` into the terminal and press enter" ] } ] }, { "id": "30", "title": "\\l", "summary": "", "content": "", "steps": [ { "id": "30.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "1c9174933ba5611d8f1c905eca81d72ca9d314ea" ] }, "content": "List the databases.", "hints": [ "Use the **l**ist shortcut command", "It's the `\\l` command", "Type `\\l` into the psql prompt and press enter", "Enter `psql --username=freecodecamp --dbname=postgres` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "40", "title": "rebuild database", "summary": "", "content": "", "steps": [ { "id": "40.1", "setup": { "watchers": [ "../.bash_history" ], "commits": [ "61098ff47c802c519064ebc73580b5f72bc32f29" ] }, "content": "Your database isn't here. You can use the `.sql` file you created at the end of Part 1 to rebuild it. I recommend \"splitting\" the terminal. You can do that by clicking the \"hamburger\" menu at the top left of the window, going to the \"Terminal\" menu, and clicking \"Split Terminal\". Once you've done that, enter `psql -U postgres < students.sql` in it to rebuild the database.", "hints": [ "Enter the suggested command in the terminal", "Make sure you are in the `project` folder first" ] } ] }, { "id": "50", "title": "\\l", "summary": "", "content": "", "steps": [ { "id": "50.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "39be444188d17f5ad4c07db9cb6920f85d15455a" ] }, "content": "A lot of stuff happened in the terminal. That looks promising. In the psql prompt, view the databases again.", "hints": [ "Use the **l**ist shortcut command", "It's the `\\l` command", "Type `\\l` into the psql prompt and press enter", "Enter `psql --username=freecodecamp --dbname=postgres` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "60", "title": "\\c students", "summary": "", "content": "", "steps": [ { "id": "60.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "add4581b538ee98c0d253d52507259efaae8965e" ] }, "content": "There's your `students` database. Connect to it.", "hints": [ "Use the **c**onnect shortcut command with the database name after it", "It's the `\\c` command", "Here's an example `\\c `", "Type `\\c students` into the psql prompt and press enter", "Enter `psql --username=freecodecamp --dbname=postgres` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "70", "title": "\\d", "summary": "", "content": "", "steps": [ { "id": "70.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "3abf2cdf207398a1b9dcc3010edd2f716fe0026b" ] }, "content": "Now that you're connected. Display the tables and relations that are here to see if it's all correct.", "hints": [ "Use the **d**isplay shortcut command", "It's the `\\d` command", "Type `\\d` into the psql prompt and press enter", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "80", "title": "\\d students", "summary": "", "content": "", "steps": [ { "id": "80.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "d0de96fc6355cbc8d15edd032af23bc346c77288" ] }, "content": "That all looks right. View the details of the `students` table to make sure the stucture is right.", "hints": [ "Use the **d**isplay shortcut command with the table name after it", "It's the `\\d` command", "Here's an example: `\\d `", "Type `\\d students` into the psql prompt and press enter", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "90", "title": "select * from students", "summary": "", "content": "", "steps": [ { "id": "90.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "91b44c64c738a98b0d35c9ba5dfb89088d719dd1" ] }, "content": "Looks good. Make sure all the data is in the table, as well.", "hints": [ "View all the data in the `students` table", "Use the `SELECT` and `FROM` keywords with `*` to view all the columns", "Here's an example: `SELECT FROM `;", "Type `SELECT * FROM students;` into the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "1220", "title": "touch student_info.sh", "summary": "", "content": "", "steps": [ { "id": "1220.1", "setup": { "watchers": [ "../.bash_history" ], "commits": [ "32a7c6b5af435987b06e52dfd613b591d3b8e903" ] }, "content": "The data is all there. You should take a look at the details of the other tables and the data in them to make sure they look good. When you are done, use `touch` in the bash terminal to create `student_info.sh`. You are going to make a script to print info about your students.", "hints": [ "Here's an example: `touch `", "Enter `touch student_info.sh` in the terminal", "The bash terminal, not the psql one", "Make sure you are in the `project` folder first" ] } ] }, { "id": "1230", "title": "chmod +x student_info.sh", "summary": "", "content": "", "steps": [ { "id": "1230.1", "setup": { "watchers": [ "../.bash_history" ], "commits": [ "2f94512d4b15118be549c952e441cce4f7ad4af0" ] }, "content": "Give your new file executable permissions.", "hints": [ "It's the `chmod` command with the `+x` flag", "Here's an example: `chmod +x `", "Type `chmod +x student_info.sh` in the terminal and press enter" ] } ] }, { "id": "1240", "title": "Add shebang", "summary": "", "content": "", "steps": [ { "id": "1240.1", "setup": { "watchers": [ "./student_info.sh" ], "commits": [ "d727d0c372ac93361c88f266c0a7f8cfab92bbb8" ] }, "content": "Add a shebang that uses bash at the top of your new script.", "hints": [ "The shebang you want is `#!/bin/bash`", "Add `#!/bin/bash` to your `student_info.sh` file" ] } ] }, { "id": "1250", "title": "Add comment", "summary": "", "content": "", "steps": [ { "id": "1250.1", "setup": { "watchers": [ "./student_info.sh" ], "commits": [ "566fdc412fd81c8f4af5ca4008844f5deb572b93" ] }, "content": "Below the shebang, add a comment that says `Info about my computer science students from students database`.", "hints": [ "Make sure it's a single line comment", "A comment look like this: `# `", "Add `# Info about my computer science students from students database` below the \"shebang\" in your `student_info.sh` file" ] } ] }, { "id": "1260", "title": "Add echo title", "summary": "", "content": "", "steps": [ { "id": "1260.1", "setup": { "watchers": [ "./student_info.sh" ], "commits": [ "c1a7be92be59d0c98e457073797d03b407d9f763" ] }, "content": "In the new script, use `echo` to print `~~ My Computer Science Students ~~`. Use the `-e` flag with it to put a new line at the beginning and end of the text.", "hints": [ "The new line character is `\\n`", "Here's an example: `echo -e \"\\n\\n\"`", "Add `echo -e \"\\n~~ My Computer Science Students ~~\\n\"` below the comment in your `student_info.sh` file" ] } ] }, { "id": "1265", "title": "./student_info.sh", "summary": "", "content": "", "steps": [ { "id": "1265.1", "setup": { "watchers": [ "../.bash_history" ], "commits": [ "d499acc38c2945bdc276d50154fa723abbbf70d1" ] }, "content": "Run the script to make sure it's working.", "hints": [ "Run your `student_info.sh` script by executing it", "Type `./student_info.sh` in the terminal and press enter", "Make sure you are in the `project` folder first" ] } ] }, { "id": "1270", "title": "Add PSQL Variable", "summary": "", "content": "", "steps": [ { "id": "1270.1", "setup": { "watchers": [ "./student_info.sh" ], "commits": [ "d7cc52e8df2f8631e4b427261e9853f8cb480890" ] }, "content": "You will want to query the database again to get info about the students to display. Add the same `PSQL` variable you use in your `insert_data.sh` script. It looked like this: `PSQL=\"psql -X --username=freecodecamp --dbname=students --no-align --tuples-only -c\"`", "hints": [ "Add the suggested variable at the bottom of the `student_info.sh` file" ] } ] }, { "id": "1280", "title": "Add echo students with 4.0", "summary": "", "content": "", "steps": [ { "id": "1280.1", "setup": { "watchers": [ "./student_info.sh" ], "commits": [ "bea5773f9848193dd2c0a638f6ca5dcce20beeaf" ] }, "content": "Below the PSQL variable you just added, use `echo` to print `First name, last name, and GPA of students with a 4.0 GPA:`. Use the `-e` flag to put a new line at the beginning of the sentence.", "hints": [ "The new line character is `\\n`", "Here's an example of the command: `echo -e \"\\n\"`", "At the bottom of the `student_info.sh` file, add this:\n```sh\necho -e \"\\nFirst name, last name, and GPA of students with a 4.0 GPA:\"\n```" ] } ] }, { "id": "1290", "title": "psql SELECT * FROM students", "summary": "", "content": "", "steps": [ { "id": "1290.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "21c135b7d5959c011f5afd22d583ecdff9fe90e2" ] }, "content": "You will want to print what that sentence is asking for. You should know how to make that query, but lets practice a little first. `SQL` stands for \"Structured Query Language\". It's the language you have been using to manage your relational databases. In the psql prompt, view all the data in the students table like you have done many times.", "hints": [ "Use the `SELECT` and `FROM` keywords with `*` to view all the data", "Enter `SELECT * FROM students;` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "1300", "title": "psql SELECT first_name", "summary": "", "content": "", "steps": [ { "id": "1300.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "0cc12d8eac48539f30b5568bff60ac1f73d57bbe" ] }, "content": "You should look at the column titles that were returned. The `*` gets all columns in a table with your query. You can return specific columns by putting the column name in the query instead of `*`. In the psql prompt, view just the `first_name` column from the `students` table.", "hints": [ "Use the `SELECT` and `FROM` keywords", "Here's an example: `SELECT FROM ;`", "Enter `SELECT first_name FROM students;` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "1310", "title": "psql SELECT first_name, last_name, gpa", "summary": "", "content": "", "steps": [ { "id": "1310.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "458b27892ccc9dbcd7dfd2dd7f5979e70e253c0f" ] }, "content": "Just the `first_name` column was returned that time. You can specify as many columns you want returned by separating them with commas. View the `first_name`, `last_name` and `gpa` columns from the `students` table.", "hints": [ "Use the `SELECT` and `FROM` keywords", "Here's an example: `SELECT , , FROM ;`", "Enter `SELECT first_name, last_name, gpa FROM students;` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already", "Don't filter any rows" ] } ] }, { "id": "1320", "title": "psql SELECT WHERE gpa < 2.5", "summary": "", "content": "", "steps": [ { "id": "1320.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "cbada490dc7105329db5f9405d27c97ea9c93af9" ] }, "content": "You can return only rows you want by adding `WHERE ` to your query. A condition can consist of a column, an operator, and a value. Use one of these to view the same columns as before but only rows `WHERE gpa < 2.5`.", "hints": [ "Here's an example: `SELECT FROM WHERE ;`", "The previous command you used was `SELECT first_name, last_name, gpa FROM students;`", "The condition you want is `WHERE gpa < 2.5`", "Enter `SELECT first_name, last_name, gpa FROM students WHERE gpa < 2.5;` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "1330", "title": "psql SELECT WHERE gpa >= 3.8", "summary": "", "content": "", "steps": [ { "id": "1330.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "bb85dfdd68291e4525eca45b9dd5cb4e199e06e5" ] }, "content": "The `<` only return rows where the `gpa` column was less than `2.5`. Some other operators are: `<`, `>`, `<=`, `>=`. View the same columns, but only rows for students with a `gpa` greater than or equal to `3.8`.", "hints": [ "The greater than or equal to operator is `>=`", "Here's an example: `SELECT FROM WHERE ;`", "The previous command you used was `SELECT first_name, last_name, gpa FROM students WHERE gpa < 2.5;`", "The condition you want here is `WHERE gpa >= 3.8`", "Enter `SELECT first_name, last_name, gpa FROM students WHERE gpa >= 3.8;` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "1340", "title": "psql SELECT WHERE != 4.0", "summary": "", "content": "", "steps": [ { "id": "1340.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "31ce05419d9acd916ebdcaeffa25f8eee8117ef0" ] }, "content": "That only returned students with a GPA of 3.8 or better. There's equal (`=`) and not equal (`!=`) operators as well. View the same columns for students that don't have a 4.0 gpa.", "hints": [ "Use the not equal (`!=`) operator", "The previous command you used was `SELECT first_name, last_name, gpa FROM students WHERE gpa >= 3.8;`", "The condition you want here is `WHERE gpa != 4.0`", "Enter `SELECT first_name, last_name, gpa FROM students WHERE gpa != 4.0;` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "1360", "title": "Add echo query result", "summary": "", "content": "", "steps": [ { "id": "1360.1", "setup": { "watchers": [ "./student_info.sh" ], "commits": [ "772044249720a9edf11f9442047bc74d6567bd39" ] }, "content": "The right query will get you only the data you are looking for. Back in your `student_info.sh` file, add an `echo` command to the bottom that prints what the sentence above it asks for. Place double quotes around it like this: `echo \"$($PSQL \"\")\"`. This will make it so the output isn't all on one line.", "hints": [ "Add `echo \"$($PSQL \"\")\"` to the bottom of the `student_info.sh` file, except with the correct query in it", "You previously used, `SELECT first_name, last_name, gpa FROM students WHERE gpa != 4.0;` in the psql prompt", "The condition you want here is `WHERE gpa = 4.0`", "Practice the query in the psql prompt to make sure it's getting what you want", "If you run your script, the last echo statement should print:\n```sh\nCasares|Hijo|4.0\nVanya|Hassanah|4.0\nDejon|Howell|4.0\n```", "Add `echo \"$($PSQL \"SELECT first_name, last_name, gpa FROM students WHERE gpa = 4.0\")\"` to the bottom of the `student_info.sh` file" ] } ] }, { "id": "1370", "title": "./student_info.sh", "summary": "", "content": "", "steps": [ { "id": "1370.1", "setup": { "watchers": [ "../.bash_history" ], "commits": [ "f149e55e59aa91db945f99cc0afd8da4bbede702" ] }, "content": "Run the script to see your students with the highest GPA's.", "hints": [ "Run your `student_info.sh` script by executing it", "Type `./student_info.sh` in the terminal and press enter", "Make sure you are in the `project` folder first" ] } ] }, { "id": "1380", "title": "Add echo courses before D", "summary": "", "content": "", "steps": [ { "id": "1380.1", "setup": { "watchers": [ "./student_info.sh" ], "commits": [ "14283e01326a9cc3416922c8f812a9abb7817bfb" ] }, "content": "Add another `echo` statement at the bottom of the script. Make it print `All course names whose first letter is before 'D' in the alphabet:`. Put a new line in front of it like the first sentence.", "hints": [ "Use `echo` with the `-e` flag and a new line character", "The new line character is `\\n`", "Here's an example of the command: `echo -e \"\\n\"`", "At the bottom of the `student_info.sh` file, add this:\n```sh\necho -e \"\\nAll course names whose first letter is before 'D' in the alphabet:\"\n```" ] } ] }, { "id": "1390", "title": "psql SELECT * FROM majors", "summary": "", "content": "", "steps": [ { "id": "1390.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "768b1db7dae189ea80a55d287f19713ddcc1a5d0" ] }, "content": "Practice first. In the psql prompt, view all the data in the `majors` table.", "hints": [ "Use the `SELECT` and `FROM` keywords with `*` to view all the data", "Enter `SELECT * FROM majors;` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "1400", "title": "psql SELECT WHERE major = Game Design", "summary": "", "content": "", "steps": [ { "id": "1400.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "dcbd4b34de107197df95f55b8028879a0e633dbc" ] }, "content": "The operators you used with numbers in the last section can be used on text as well. Use the `=` to view all majors named `Game Design`. Don't forget that You need single quotes around text values.", "hints": [ "Use the `SELECT`, `FROM`, and `WHERE` keywords with `*` to view the suggested rows", "Here's an example: `SELECT FROM WHERE ;`", "The condition you want is `major = 'Game Design'`", "Enter `SELECT * FROM majors WHERE major = 'Game Design';` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "1410", "title": "psql SELECT WHERE major != Game Design", "summary": "", "content": "", "steps": [ { "id": "1410.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "366cc9376cc4c5ae6d48cb30e85b61693ab3f15c" ] }, "content": "Next, view all the rows not equal to `Game Design`.", "hints": [ "The not equal operator is `!=`", "Use the `SELECT`, `FROM`, and `WHERE` keywords with `*` to view the suggested rows", "Here's an example: `SELECT FROM
WHERE ;`", "The condition you want is `major != 'Game Design'`", "Enter `SELECT * FROM majors WHERE major != 'Game Design';` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "1420", "title": "psql SELECT WHERE major > Game Design", "summary": "", "content": "", "steps": [ { "id": "1420.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "b53605fb63de0e23e2d2db1186bb32649de7781f" ] }, "content": "Use the greater than operator to see majors that come after it alphabetically.", "hints": [ "The greater than operator is `>`", "You want to see what rows are `> 'Game Design'`", "Use the `SELECT`, `FROM`, and `WHERE` keywords with `*` to view the suggested rows", "Here's an example: `SELECT FROM
WHERE ;`", "The condition you want is `major > 'Game Design'`", "Enter `SELECT * FROM majors WHERE major > 'Game Design';` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "1430", "title": "psql SELECT WHERE major >= Game Design", "summary": "", "content": "", "steps": [ { "id": "1430.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "89e0865d5a69dd8e08adc11e914c02b01dc5e91f" ] }, "content": "`Game Design` was not included in the results because it is not `> 'Game Design'`. Try it with the greater than or equal to operator.", "hints": [ "The greater than or equal to operator is `>=`", "You want to see what rows are `>= 'Game Design'`", "Use the `SELECT`, `FROM`, and `WHERE` keywords with `*` to view the suggested rows", "Here's an example: `SELECT FROM
WHERE ;`", "The condition you want is `major >= 'Game Design'`", "Enter `SELECT * FROM majors WHERE major >= 'Game Design';` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "1440", "title": "psql SELECT WHERE major < G", "summary": "", "content": "", "steps": [ { "id": "1440.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "b036ae1026e8aada92fe99d8dd447ce81fcad668" ] }, "content": "It included `Game Design` in the results that time. So if you want to see results that start with a `G` or after, you could use `major >= 'G'`. View the majors that come before `G`.", "hints": [ "Use the less than (`<`) operator to see rows that come before `G`", "Use the `SELECT`, `FROM`, and `WHERE` keywords with `*` to view the suggested rows", "Here's an example: `SELECT FROM
WHERE ;`", "The condition you want is `major < 'G'`", "Enter `SELECT * FROM majors WHERE major < 'G';` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "1450", "title": "Add echo query result", "summary": "", "content": "", "steps": [ { "id": "1450.1", "setup": { "watchers": [ "./student_info.sh" ], "commits": [ "123186d0509c656d61d18c3b08465c3a7bc6d8b7" ] }, "content": "In your script, add an `echo` at the bottom to print the suggested info like you did before. Make sure to use double quotes where needed.", "hints": [ "Add `echo \"$($PSQL \"\")\"` to the bottom of the `student_info.sh` file, except with the correct query in it", "You previously used, `SELECT * FROM majors WHERE major < 'G';` in the psql prompt", "The condition you want here is `WHERE course < 'D'`", "You only want to get the `course` column from the `courses` table", "Practice the query in the psql prompt to make sure it's getting what you want", "If you run your script, the last echo statement should print:\n```sh\nComputer Networks\nComputer Systems\nArtificial Intelligence\nCalculus\nAlgorithms\n```", "Add `echo \"$($PSQL \"SELECT course FROM courses WHERE course < 'D'\")\"` to the bottom of the `student_info.sh` file" ] } ] }, { "id": "1460", "title": "./student_info.sh", "summary": "", "content": "", "steps": [ { "id": "1460.1", "setup": { "watchers": [ "../.bash_history" ], "commits": [ "4e8d4f09ef41cec8bf4f3d7d578c9b341603302f" ] }, "content": "Run the script to see what course names come before the letter `D`.", "hints": [ "Run your `student_info.sh` script by executing it", "Type `./student_info.sh` in the terminal and press enter", "Make sure you are in the `project` folder first" ] } ] }, { "id": "1470", "title": "Add echo students after R with gpa above 3.8 or below 2.0", "summary": "", "content": "", "steps": [ { "id": "1470.1", "setup": { "watchers": [ "./student_info.sh" ], "commits": [ "9ed5bd7f539d106b44754d5074ea123a0f6cd30b" ] }, "content": "Looks like there is five of them. Add another sentence like the others that says: `First name, last name, and GPA of students whose last name begins with an 'R' or after and have a GPA greater than 3.8 or less than 2.0:`", "hints": [ "At the bottom of the file, use `echo` with the `-e` flag and a new line character again to print the suggested sentence", "The new line character is `\\n`", "Here's an example of the command: `echo -e \"\\n\"`", "At the bottom of the `student_info.sh` file, add this:\n```sh\necho -e \"\\nFirst name, last name, and GPA of students whose last name begins with an 'R' or after and have a GPA greater than 3.8 or less than 2.0:\"\n```" ] } ] }, { "id": "1480", "title": "psql SELECT * FROM students", "summary": "", "content": "", "steps": [ { "id": "1480.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "cbc752c258477be641b260fd96357bc28844fa9e" ] }, "content": "To find that, start by using the psql prompt to view all the data in the `students` table.", "hints": [ "Use the `SELECT` and `FROM` keywords with `*` to view all the data", "Enter `SELECT * FROM students;` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "1490", "title": "psql SELECT WHERE last_name < M", "summary": "", "content": "", "steps": [ { "id": "1490.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "5c55a9fdf16347a27ee2b4b591bd0b93a7b9e226" ] }, "content": "It returned 31 rows. Use the same command, but only return the rows for students whose last name comes before `M` in the alphabet.", "hints": [ "Use the less than (`<`) operator to see rows that come before `M`", "Use the `SELECT`, `FROM`, and `WHERE` keywords with `*` to view the suggested rows", "Here's an example: `SELECT FROM
WHERE ;`", "The condition you want is `last_name < 'M'`", "Enter `SELECT * FROM students WHERE last_name < 'M';` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "1500", "title": "SELECT WHERE last_name < M OR gpa = 3.9", "summary": "", "content": "", "steps": [ { "id": "1500.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "e17833f1e2c84c59e7b78f0204c3bd431dfa6f1e" ] }, "content": "That returned 18 rows. You can use multiple conditions after `WHERE` with `AND` or `OR`, among others. Just add the keyword and another condition. In the psql prompt, use the same command as before, but add an `OR` to also return rows of students with a 3.9 GPA.", "hints": [ "The previous command was: `SELECT * FROM students WHERE last_name < 'M';`", "Here's an example of the `WHERE` part: `WHERE OR `", "Add an `OR ` to the previous command", "The condition you want to add is `OR gpa = 3.9`", "The whole condition is `WHERE last_name < 'M' OR gpa = 3.9`", "Enter `SELECT * FROM students WHERE last_name < 'M' OR gpa = 3.9;` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "1510", "title": "psql SELECT WHERE last_name < M AND gpa = 3.9", "summary": "", "content": "", "steps": [ { "id": "1510.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "9c13b9e4ffb437d3aa9d3e63c8705190b3e6d98a" ] }, "content": "It showed rows where one of the conditions was true, there was one more than last time. Enter the previous command, but use `AND` to view only students that meet both conditions.", "hints": [ "The previous command was: `SELECT * FROM students WHERE last_name < 'M' OR gpa = 3.9;`", "Here's an example of the `WHERE` part: `WHERE AND `", "Enter `SELECT * FROM students WHERE last_name < 'M' AND gpa = 3.9;` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "1520", "title": "psql SELECT WHERE last_name < M AND gpa = 3.9 OR gpa < 2.3", "summary": "", "content": "", "steps": [ { "id": "1520.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "29fcb2b618476b74d70b3af6386c679b9d316968" ] }, "content": "Now it only shows rows where both conditions are true, one person. Enter the previous command, but add a third condition of `OR gpa < 2.3`.", "hints": [ "The previous command was: `SELECT * FROM students WHERE last_name < 'M' OR gpa = 3.9;`", "Here's an example of the `WHERE` part: `WHERE AND OR `", "The conditions look like this: `WHERE last_name < 'M' AND gpa = 3.9 OR gpa < 2.3;`", "Enter `SELECT * FROM students WHERE last_name < 'M' AND gpa = 3.9 OR gpa < 2.3;` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "1530", "title": "psql SELECT WHERE last_name < M AND (gpa = 3.9 OR gpa < 2.3)", "summary": "", "content": "", "steps": [ { "id": "1530.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "63eb0d87e3c6aa7f21fcc3339f7009585a1f964a" ] }, "content": "This showed all students whose GPA is less than 2.3 because the final `OR` condition was true for them. It didn't matter what their last name started with. You can group conditions together with parenthesis like this: `WHERE AND ( OR )`. This would only return rows where `` is true and one of the others is true. View students whose last name is before `M` that have a GPA of 3.9 or less than 2.3.", "hints": [ "The previous command was: `SELECT * FROM students WHERE last_name < 'M' OR gpa = 3.9 OR gpa < 2.3;`", "Enter the previous command but group your conditions with parenthesis to only view the suggested rows", "Enter `SELECT * FROM students WHERE last_name < 'M' AND (gpa = 3.9 OR gpa < 2.3);` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "1540", "title": "Add echo query result", "summary": "", "content": "", "steps": [ { "id": "1540.1", "setup": { "watchers": [ "./student_info.sh" ], "commits": [ "25d7b5d48ae3d14fd8b8169ec82410b1685c63ae" ] }, "content": "Two students meet those conditions. Back in the student info file, add an echo command at the bottom to print the suggested rows.", "hints": [ "Add `echo \"$($PSQL \"\")\"` to the bottom of the `student_info.sh` file, except with the correct query in it", "You previously used `SELECT * FROM students WHERE last_name < 'M' AND (gpa = 3.9 OR gpa < 2.3);` in the psql prompt", "Practice the query in the psql prompt to make sure it's getting what you want", "The conditions should be `last_name >= 'R' AND (gpa > 3.8 OR gpa < 2.0)`", "If you run your script, the last echo statement should print:\n```sh\nEfren|Reilly|3.9\nMariana|Russel|1.8\nMehdi|Vandenberghe|1.9\n```", "Add `echo \"$($PSQL \"SELECT first_name, last_name, gpa FROM students WHERE last_name >= 'R' AND (gpa > 3.8 OR gpa < 2.0)\")\"` to the bottom of the `student_info.sh` file" ] } ] }, { "id": "1550", "title": "./student_info", "summary": "", "content": "", "steps": [ { "id": "1550.1", "setup": { "watchers": [ "../.bash_history" ], "commits": [ "86ec15cc0ce40f13016a570583f8f798a9e6eb72" ] }, "content": "Run the script to see the results.", "hints": [ "Run your `student_info.sh` script by executing it", "Type `./student_info.sh` in the terminal and press enter", "Make sure you are in the `project` folder first" ] } ] }, { "id": "1560", "title": "Add echo students containing sa or r as second to last letter", "summary": "", "content": "", "steps": [ { "id": "1560.1", "setup": { "watchers": [ "./student_info.sh" ], "commits": [ "88b2080cd868d03e3ad04a7c2aa1138f8d86eabe" ] }, "content": "Moving along. Add another `echo` command, like the others, with a sentence that says: `Last name of students whose last name contains a case insensitive 'sa' or have an 'r' as the second to last letter:`", "hints": [ "At the bottom of the file, use `echo` with the `-e` flag and a new line character again to print the suggested sentence", "The new line character is `\\n`", "Here's an example of the command: `echo -e \"\\n\"`", "At the bottom of the `student_info.sh` file, add this:\n```sh\necho -e \"\\nLast name of students whose last name contains a case insensitive 'sa' or have an 'r' as the second to last letter:\"\n```" ] } ] }, { "id": "1570", "title": "psql SELECT * FROM courses", "summary": "", "content": "", "steps": [ { "id": "1570.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "874793bec84eac07079026bb570b97640d09974a" ] }, "content": "Start by viewing everything from the `courses` table in the psql prompt to see how you might be able to find this out.", "hints": [ "Use the `SELECT` and `FROM` keywords with `*` to view all the data", "Enter `SELECT * FROM courses;` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "1580", "title": "psql SELECT WHERE course LIKE _lgorithms", "summary": "", "content": "", "steps": [ { "id": "1580.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "45fe881bf046871746ab042ac4bbe627b599e71c" ] }, "content": "There's a few that contain the word `Algorithms`. You can use `LIKE` to find patterns in text like this: `WHERE LIKE ''`. An underscore (`_`) in a pattern will return rows that have any character in that spot. View the rows in this table with a course name that matches the pattern `'_lgorithms'`.", "hints": [ "Here's an example: `SELECT * FROM courses WHERE course LIKE '';`", "Enter `SELECT * FROM courses WHERE course LIKE '_lgorithms';` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "1590", "title": "psql SELECT WHERE course LIKE %lgorithms", "summary": "", "content": "", "steps": [ { "id": "1590.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "5bbbfc42bede5c66fde716a220f90c1225eea168" ] }, "content": "That pattern matched only rows that had exactly one character, followed by `lgorithms`. Another pattern character is `%`. It means anything can be there. To find names that start with `W`, you could use `W%`. View the courses that end in `lgorithms`.", "hints": [ "Use `LIKE` and a pattern with `%` to view the courses ending in `lgorithms`", "Here's an example: `SELECT * FROM courses WHERE course LIKE '';`", "The pattern you want is `%lgorithms`", "Enter `SELECT * FROM courses WHERE course LIKE '%lgorithms';` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "1600", "title": "psql SELECT WHERE course LIKE Web%", "summary": "", "content": "", "steps": [ { "id": "1600.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "a381859d6dcc54b3578293b645b587eff77dc737" ] }, "content": "It found two that time. Try viewing courses that start with `Web`.", "hints": [ "Use `LIKE` and a pattern with `%` to view the courses starting with `Web`", "Here's an example: `SELECT * FROM courses WHERE course LIKE '';`", "The pattern you want is `Web%`", "Enter `SELECT * FROM courses WHERE course LIKE 'Web%';` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "1610", "title": "psql SELECT WHERE course LIKE _e%", "summary": "", "content": "", "steps": [ { "id": "1610.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "344b93fb7244d8703dc3afa61e9ad7b9280a92d9" ] }, "content": "Combine the two pattern matching characters to show courses that have a second letter of `e`.", "hints": [ "Use `LIKE` and a pattern with `_` and `%` to view the courses whose second letter is `e`", "Here's an example: `SELECT * FROM courses WHERE course LIKE '';`", "Remember that the `_` will match any single character and `%` will match any number of characters", "The pattern you want is `_e%`", "Enter `SELECT * FROM courses WHERE course LIKE '_e%';` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "1620", "title": "psql SELECT WHERE course LIKE % %", "summary": "", "content": "", "steps": [ { "id": "1620.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "581e676fa60d18a9fab6695b36e4ca0bf04ce1a0" ] }, "content": "Nice job! Try viewing the courses with a space in their names.", "hints": [ "Use `LIKE` and a pattern with two `%` to view the courses with a space", "Here's an example: `SELECT * FROM courses WHERE course LIKE '';`", "The pattern you want is `% %`", "Enter `SELECT * FROM courses WHERE course LIKE '% %';` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "1630", "title": "psql SELECT WHERE course NOT LIKE % %", "summary": "", "content": "", "steps": [ { "id": "1630.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "8191749803f09646f0fe0ce821a88043539949b0" ] }, "content": "There they are. You can use `NOT LIKE` to find things that don't match a pattern. View courses that don't contain a space.", "hints": [ "Use `NOT LIKE` and a pattern with two `%`'s to view the courses without a space", "Here's an example: `SELECT * FROM courses WHERE course NOT LIKE '';`", "The pattern you want is `% %`", "Enter `SELECT * FROM courses WHERE course NOT LIKE '% %';` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "1640", "title": "psql SELECT WHERE course LIKE %A%", "summary": "", "content": "", "steps": [ { "id": "1640.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "247b2f45c1ecd6a36f985f81426d128308976c13" ] }, "content": "Five courses without a space. Try finding the ones that contain an `A`.", "hints": [ "Use `LIKE` and a pattern with two `%`'s to view the courses containing `A`", "Here's an example: `SELECT * FROM courses WHERE course LIKE '';`", "The pattern you want is `%A%`", "Enter `SELECT * FROM courses WHERE course LIKE '%A%';` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "1650", "title": "psql SELECT WHERE course ILIKE %A%", "summary": "", "content": "", "steps": [ { "id": "1650.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "f0263bfcf5a9105b8863d8c5fb452d3bbc660af5" ] }, "content": "6 rows. This showed all the courses with a capital `A`. `ILIKE` will ignore the case of the letters when matching. Use it to see the courses with an `A` or `a`.", "hints": [ "Use `ILIKE` and a pattern with two `%`'s to view the courses containing `A` in any case", "Here's an example: `SELECT * FROM courses WHERE course ILIKE '';`", "The pattern you want is `%A%`", "Enter `SELECT * FROM courses WHERE course ILIKE '%A%';` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "1670", "title": "psql SELECT WHERE course NOT ILIKE %a%", "summary": "", "content": "", "steps": [ { "id": "1670.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "4983bac8f9146fc0f547d4fb83785af21ffce728" ] }, "content": "It found 11 rows that time. You can put `NOT` in front of `ILIKE` as well. Use it to see the courses that don't contain an `A` or `a`.", "hints": [ "Use `NOT ILIKE` and a pattern with two `%`'s to view the courses not containing `A` in any case", "Here's an example: `SELECT * FROM courses WHERE course NOT ILIKE '';`", "The pattern you want is `%A%`", "Enter `SELECT * FROM courses WHERE course NOT ILIKE '%A%';` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "1680", "title": "psql SELECT WHERE course NOT ILIKE %A% AND LIKE % %", "summary": "", "content": "", "steps": [ { "id": "1680.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "c18eea742ac3d5446489e5ab8db6d93a90368692" ] }, "content": "You combine these like any other conditions. View the courses that don't have a capital or lowercase `A` and have a space.", "hints": [ "Use two conditions, one with `NOT ILIKE` and one with `LIKE`", "Here's an example: `SELECT * FROM courses WHERE course NOT ILIKE '' AND course LIKE ;`", "The two patterns you want are `%A%` and `% %`", "Enter `SELECT * FROM courses WHERE course NOT ILIKE '%A%' AND course LIKE '% %';` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "1690", "title": "Add echo query result", "summary": "", "content": "", "steps": [ { "id": "1690.1", "setup": { "watchers": [ "./student_info.sh" ], "commits": [ "07db2a76f30816df0977cab66f5a378675a97d3b" ] }, "content": "In your student info script, add an `echo` statement at the bottom like the other to print the results of the suggested query.", "hints": [ "Add `echo \"$($PSQL \"\")\"` to the bottom of the `student_info.sh` file, except with the correct query in it", "You previously used `SELECT * FROM courses WHERE course NOT ILIKE '%A%' AND course LIKE '% %';` in the psql prompt", "Practice the query in the psql prompt to make sure it's getting what you want", "The conditions should be `last_name ILIKE '%sa%' OR last_name LIKE %r_`", "If you run your script, the last echo statement should print:\n```sh\nGilbert\nSavage\nSaunders\nHilpert\nHassanah\n```", "Add `echo \"$($PSQL \"SELECT last_name FROM students WHERE last_name ILIKE '%sa%' OR last_name LIKE '%r_'\")\"` to the bottom of the `student_info.sh` file" ] } ] }, { "id": "1700", "title": "./student_info.sh", "summary": "", "content": "", "steps": [ { "id": "1700.1", "setup": { "watchers": [ "../.bash_history" ], "commits": [ "5ae35d32e7e6496d2a8501af6675e166935f86ae" ] }, "content": "Run the script to see the results.", "hints": [ "Run your `student_info.sh` script by executing it", "Type `./student_info.sh` in the terminal and press enter", "Make sure you are in the `project` folder first" ] } ] }, { "id": "1710", "title": "Add echo students without major begin with D or gpa > 3.0", "summary": "", "content": "", "steps": [ { "id": "1710.1", "setup": { "watchers": [ "./student_info.sh" ], "commits": [ "012ea93a59f43c86d1c6e6227f7840b3ef063866" ] }, "content": "Looks like five students meet those conditions. Add another `echo` command at the bottom, like the others. Make this one say: `First name, last name, and GPA of students who have not selected a major and either their first name begins with 'D' or they have a GPA greater than 3.0:`", "hints": [ "At the bottom of the file, use `echo` with the `-e` flag and a new line character again to print the suggested sentence", "The new line character is `\\n`", "Here's an example of the command: `echo -e \"\\n\"`", "At the bottom of the `student_info.sh` file, add this:\n```sh\necho -e \"\\nFirst name, last name, and GPA of students who have not selected a major and either their first name begins with 'D' or they have a GPA greater than 3.0:\"\n```" ] } ] }, { "id": "1715", "title": "psql SELECT * FROM students", "summary": "", "content": "", "steps": [ { "id": "1715.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "32a27ae56690fd07a4dc997073dbe14feedd8ee3" ] }, "content": "Start by looking at all the data in the students table.", "hints": [ "Use the `SELECT` and `FROM` keywords with `*` to view all the data", "Enter `SELECT * FROM students;` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "1720", "title": "psql SELECT * FROM students WHERE gpa IS NULL", "summary": "", "content": "", "steps": [ { "id": "1720.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "c31a0ca1f4b5bb767fb49840a8a0d2d3cb904a3c" ] }, "content": "All the fields that are empty or blank are `null`. You can access them using `IS NULL` as a condition like this: `WHERE IS NULL`. View the students who don't have a GPA.", "hints": [ "Use the `SELECT`, `FROM`, `WHERE`, and `IS NULL` keywords with `*` to view the suggested rows", "Here's an example: `SELECT FROM
WHERE ;`", "The condition you want is `gpa IS NULL`", "Enter `SELECT * FROM students WHERE gpa IS NULL;` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "1730", "title": "psql SELECT WHERE gpa IS NOT NULL", "summary": "", "content": "", "steps": [ { "id": "1730.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "810b2e495c57ea69579f493fcf050010685cfa4b" ] }, "content": "Inversely, you can use `IS NOT NULL` to see rows that aren't null. View all the info on students that do have a GPA.", "hints": [ "Use the `SELECT`, `FROM`, `WHERE`, and `IS NOT NULL` keywords with `*` to view the suggested rows", "Here's an example: `SELECT FROM
WHERE ;`", "The condition you want is `gpa IS NOT NULL`", "Enter `SELECT * FROM students WHERE gpa IS NOT NULL;` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "1740", "title": "psql SELECT WHERE major IS NULL", "summary": "", "content": "", "steps": [ { "id": "1740.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "8566db81104f266e4a7d8da5554eefd82c8af647" ] }, "content": "View all the info on students who haven't chosen a major.", "hints": [ "A null `major_id` field means that student hasn't chosen a major", "Use the `SELECT`, `FROM`, `WHERE`, and `IS NULL` keywords with `*` to view the suggested rows", "Here's an example: `SELECT FROM
WHERE ;`", "The condition you want is `major_id IS NULL`", "Enter `SELECT * FROM students WHERE major_id IS NULL;` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "1750", "title": "psql SELECT WHERE major IS NULL and gpa IS NOT NULL", "summary": "", "content": "", "steps": [ { "id": "1750.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "f66ec08e83e6c2683429930f41754dba41a1a9cd" ] }, "content": "View the students who don't have a major, but don't include students without a GPA.", "hints": [ "Use the `SELECT`, `FROM`, `WHERE`, `IS NULL`, `AND` and `IS NOT NULL` keywords with `*` to view the suggested rows", "Here's an example: `SELECT FROM
WHERE AND ;`", "The condition you want is `major_id IS NULL AND gpa IS NOT NULL`", "Enter `SELECT * FROM students WHERE major_id IS NULL AND gpa IS NOT NULL;` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "1760", "title": "psql SELECT WHERE major_id IS NULL AND gpa IS NULL", "summary": "", "content": "", "steps": [ { "id": "1760.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "d864849e60042b268ab2dd7900144015bac47b74" ] }, "content": "One more. View the students who don't have a major and gpa.", "hints": [ "Use the `SELECT`, `FROM`, `WHERE`, `IS NULL`, and `AND` keywords with `*` to view the suggested rows", "Here's an example: `SELECT FROM
WHERE AND ;`", "The condition you want is `major_id IS NULL AND gpa IS NULL`", "Enter `SELECT * FROM students WHERE major_id IS NULL AND gpa IS NULL;` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "1770", "title": "Add echo query result", "summary": "", "content": "", "steps": [ { "id": "1770.1", "setup": { "watchers": [ "./student_info.sh" ], "commits": [ "7d0e8e68561788019201ed0214bc926ab1dfedb0" ] }, "content": "In your script, add an `echo` command at the bottom to print the results the sentence is looking for.", "hints": [ "Add `echo \"$($PSQL \"\")\"` to the bottom of the `student_info.sh` file, except with the correct query in it", "Practice the query in the psql prompt to make sure it's getting what you want", "You will need to use the `SELECT`, `FROM`, `WHERE`, `IS NULL`, `AND`, `LIKE`, and `OR` keywords", "If you run your script, the last echo statement should print:\n```sh\nNoe|Savage|3.6\nDanh|Nhung|2.4\nHugo|Duran|3.8\n```", "You previously used `SELECT * FROM students WHERE last_name < 'M' AND (gpa = 3.9 OR gpa < 2.3);` in the psql prompt", "Here's an example of the conditions you want: `WHERE AND ( OR )`", "The conditions should look like this: `WHERE major_id IS NULL AND (first_name LIKE 'D%' OR gpa > 3.0)`", "Add `echo \"$($PSQL \"SELECT first_name, last_name, gpa FROM students WHERE major_id IS NULL AND (first_name LIKE 'D%' OR gpa > 3.0)\")\"` to the bottom of the `student_info.sh` file" ] } ] }, { "id": "1780", "title": "./student_info.sh", "summary": "", "content": "", "steps": [ { "id": "1780.1", "setup": { "watchers": [ "../.bash_history" ], "commits": [ "231b9d54c8487b7acfa00600618e86bd322d46aa" ] }, "content": "Run the script to see the students that meet those conditions.", "hints": [ "Run your `student_info.sh` script by executing it", "Type `./student_info.sh` in the terminal and press enter", "Make sure you are in the `project` folder first" ] } ] }, { "id": "1790", "title": "Add echo first five courses", "summary": "", "content": "", "steps": [ { "id": "1790.1", "setup": { "watchers": [ "./student_info.sh" ], "commits": [ "9ab58561833bd36e062489ebf926d50515ccbbc4" ] }, "content": "There's three of them. Add another sentence, like the others that says `Course name of the first five courses, in reverse alphabetical order, that have an 'e' as the second letter or end with an 's':`", "hints": [ "At the bottom of the file, use `echo` with the `-e` flag and a new line character again to print the suggested sentence", "The new line character is `\\n`", "Here's an example of the command: `echo -e \"\\n\"`", "At the bottom of the `student_info.sh` file, add this:\n```sh\necho -e \"\\nCourse name of the first five courses, in reverse alphabetical order, that have an 'e' as the second letter or end with an 's':\"\n```" ] } ] }, { "id": "1800", "title": "psql SELECT students ORDER BY gpa", "summary": "", "content": "", "steps": [ { "id": "1800.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "d7affaa2105d1e5cfe989844f363d42dff84f3c6" ] }, "content": "You can specify the order you want your results to be in by adding `ORDER BY ` at the end of a query. In the psql prompt, view all the info in the `students` table in order by the GPA's.", "hints": [ "Use the `SELECT`, `FROM`, `WHERE`, and `ORDER BY` keywords with `*` to view the suggested rows", "Here's an example: `SELECT FROM
ORDER BY ;`", "You want to use `ORDER BY gpa` at the end of the query", "Enter `SELECT * FROM students ORDER BY gpa;` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "1810", "title": "psql SELECT students ORDER BY gpa DESC", "summary": "", "content": "", "steps": [ { "id": "1810.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "a347ea159fca6fe35cc58016089a3f937b13e25a" ] }, "content": "That put the lowest GPA's at the top. When using `ORDER BY`, it will be in ascending (`ASC`) order by default. Add `DESC` (descending) at the end of the last query to put the highest ones at the top.", "hints": [ "The last command was `SELECT * FROM students ORDER BY gpa;`", "Add `DESC` to the end of the last command", "Enter `SELECT * FROM students ORDER BY gpa DESC;` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "1820", "title": "psql SELECT students ORDER BY gpa DESC, first_name", "summary": "", "content": "", "steps": [ { "id": "1820.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "f5a825561e63d37c86fa236edad37f72fe3c1843" ] }, "content": "Now, the highest GPA's are at the top. You can add more columns to the order by separating them with a comma like this: `ORDER BY , `. Any matching values in the first ordered column will then be ordered by the next. View all the student info with the highest GPA's at the top, and in alphabetical order by `first_name` if the GPA's match.", "hints": [ "Here's an example: `SELECT FROM
ORDER BY DESC, ;`", "You want to use `ORDER BY gpa DESC, first_name` for the order", "Enter `SELECT * FROM students ORDER BY gpa DESC, first_name;` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "1830", "title": "psql SELECT students ORDER BY gpa DESC, first_name LIMIT 10", "summary": "", "content": "", "steps": [ { "id": "1830.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "519f8a9c4e459905a251bb6a1f21c23340b4333a" ] }, "content": "Many times, you only want to return a certain number of rows. You can add `LIMIT ` at the end of the query to only get the amount you want. View the students in the same order as the last command, but only return the first 10 rows.", "hints": [ "The last command was `SELECT * FROM students ORDER BY gpa DESC, first_name;`", "Add `LIMIT 10` to the end of the last command", "Enter `SELECT * FROM students ORDER BY gpa DESC, first_name LIMIT 10;` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "1835", "title": "psql SELECT students WHERE gpa IS NOT NULL ORDER BY gpa DESC, first_name LIMIT 10", "summary": "", "content": "", "steps": [ { "id": "1835.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "6281c3088ce13208f9b8d5943fb1e6934df11d97" ] }, "content": "The order of the keywords in your query matters. You cannot put `LIMIT` before `ORDER BY`, or either of them before `WHERE`. View the same number of students, in the same order, but don't get the ones who don't have a GPA.", "hints": [ "The last command was `SELECT * FROM students ORDER BY gpa DESC, first_name LIMIT 10;`", "The keywords you want are `SELECT`, `FROM`, `WHERE`, `IS NOT NULL`, `ORDER BY`, and `LIMIT`, in that order", "Here's an example: `SELECT FROM
WHERE ORDER BY LIMIT ;`", "The condition you want is `gpa IS NOT NULL`", "Enter `SELECT * FROM students WHERE gpa IS NOT NULL ORDER BY gpa DESC, first_name LIMIT 10;` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "1840", "title": "Add echo query result", "summary": "", "content": "", "steps": [ { "id": "1840.1", "setup": { "watchers": [ "./student_info.sh" ], "commits": [ "999687f942b3f3864b396142f817661619dab816" ] }, "content": "In your script, add the `echo` command to print the rows the sentence is asking for.", "hints": [ "Add `echo \"$($PSQL \"\")\"` to the bottom of the `student_info.sh` file, except with the correct query in it", "If you run your script, the last echo statement should print:\n```sh\nWeb Programming\nWeb Applications\nServer Administration\nNetwork Security\nDatabase Systems\n```", "Practice the query in the psql prompt to make sure it's getting what you want", "You will need the `SELECT`, `FROM`, `WHERE`, `LIKE`, `OR`, `ORDER BY`, `DESC`, and `LIMIT` keywords", "Add `echo \"$($PSQL \"SELECT course FROM courses WHERE course LIKE '_e%' OR course LIKE '%s' ORDER BY course DESC LIMIT 5\")\"` to the bottom of the `student_info.sh` file" ] } ] }, { "id": "1850", "title": "./student_info.sh", "summary": "", "content": "", "steps": [ { "id": "1850.1", "setup": { "watchers": [ "../.bash_history" ], "commits": [ "7e0b5bc01303e9d3a1ce5b7f7fae468401a59aae" ] }, "content": "Run the script to see the courses.", "hints": [ "Run your `student_info.sh` script by executing it", "Type `./student_info.sh` in the terminal and press enter", "Make sure you are in the `project` folder first" ] } ] }, { "id": "1860", "title": "Add echo average GPA to two decimal places", "summary": "", "content": "", "steps": [ { "id": "1860.1", "setup": { "watchers": [ "./student_info.sh" ], "commits": [ "452fb04acfea5c7d5db1764fd07ba4e74358b976" ] }, "content": ":sunglasses: Add another `echo` command at the bottom of the script like the others. Make this one say, `Average GPA of all students rounded to two decimal places:`", "hints": [ "At the bottom of the file, use `echo` with the `-e` flag and a new line character again to print the suggested sentence", "The new line character is `\\n`", "Here's an example of the command: `echo -e \"\\n\"`", "At the bottom of the `student_info.sh` file, add this:\n```sh\necho -e \"\\nAverage GPA of all students rounded to two decimal places:\"\n```" ] } ] }, { "id": "1870", "title": "psql SELECT MIN(gpa)", "summary": "", "content": "", "steps": [ { "id": "1870.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "e889d5bc63112a51de933429165bf31a9e2c62ac" ] }, "content": "There's a number of mathematic functions to use with numerical columns. One of them is `MIN`, you can use it when selecting a column like this: `SELECT MIN() FROM
`. It will find the lowest value in the column. In the psql prompt, view the lowest value in the `gpa` column of the `students` table.", "hints": [ "Enter `SELECT MIN(gpa) FROM students;` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "1880", "title": "psql SELECT MAX(gpa)", "summary": "", "content": "", "steps": [ { "id": "1880.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "e51a1d9876889777a9be0c265dc975bb992c3018" ] }, "content": "Another one is `MAX`, use it to see the largest `gpa` of the same table.", "hints": [ "You previously used `SELECT MIN(gpa) FROM students;`", "Enter `SELECT MAX(gpa) FROM students;` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "1890", "title": "psql SELECT SUM major_id", "summary": "", "content": "", "steps": [ { "id": "1890.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "bb9b16999232c49c3cb70c7c14cf32d7a6fd454d" ] }, "content": "In the same fashion, use a `SUM` function find out what all the values of the `major_id` column in the `students` table add up to.", "hints": [ "Use `SUM` like you used `MIN` and `MAX`", "You previously used `SELECT MAX(gpa) FROM students;`", "Enter `SELECT SUM(major_id) FROM students;` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "1900", "title": "psql SELECT AVG(major_id)", "summary": "", "content": "", "steps": [ { "id": "1900.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "7be2deac4882b7f230b4b5a354599d80f8a454a8" ] }, "content": "`AVG` will give you the average of all the values in a column. Use it to see the average of the same column.", "hints": [ "It's the `major_id` column in the `students` table", "Use `AVG` like you used `SUM`, `MIN` and `MAX`", "You previously used `SELECT SUM(major_id) FROM students;`", "Enter `SELECT AVG(major_id) FROM students;` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "1910", "title": "psql SELECT CEIL(AVG(major_id))", "summary": "", "content": "", "steps": [ { "id": "1910.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "1c7b61b9d0fa9f4f3bdc498011ac2404bd4084eb" ] }, "content": "You can round decimals up or down to the nearest whole number with `CEIL` and `FLOOR`, respectively. Use `CEIL` to round the average `major_id` up to the nearest whole number. Here's an example: `CEIL()`.", "hints": [ "Here's another example: `CEIL()`", "You previously used `SELECT AVG(major_id) FROM students;` to get the average", "Put `AVG(major_id)` inside the parenthesis of the `CEIL` function", "Enter `SELECT CEIL(AVG(major_id)) FROM students;` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "1920", "title": "psql SELECT ROUND(AVG(major_id))", "summary": "", "content": "", "steps": [ { "id": "1920.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "411c2365b5bee473ca40370c556e4302214b9ef5" ] }, "content": "Or, you can round a number to the nearest whole number with `ROUND`. Use it to round the average of the `major_id` column to the nearest whole number.", "hints": [ "Here's an example: `ROUND()`", "You previously used `SELECT CEIL(AVG(major_id)) FROM students;` to round a number up", "Put `AVG(major_id)` inside the parenthesis of the `ROUND` function", "Enter `SELECT ROUND(AVG(major_id)) FROM students;` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "1930", "title": "psql SELECT ROUND(AVG(major_id),5)", "summary": "", "content": "", "steps": [ { "id": "1930.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "96ba6f8b691672fb3006b79a769eba47f5664a37" ] }, "content": "You can round to a specific number of decimal places by adding a comma and number to `ROUND`, like this: `ROUND(, )`. Round the average of the `major_id` to five decimal places.", "hints": [ "You previously used `SELECT ROUND(AVG(major_id)) FROM students;` to get the average", "Put `AVG(major_id), 5` inside the parenthesis of the `ROUND` function", "Enter `SELECT ROUND(AVG(major_id), 5) FROM students;` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "1940", "title": "Add echo query result", "summary": "", "content": "", "steps": [ { "id": "1940.1", "setup": { "watchers": [ "./student_info.sh" ], "commits": [ "951d94100e97d8eaae568f0459770428041790b8" ] }, "content": "You should be able to find what your script is asking for now. Add the command to print it.", "hints": [ "Add `echo \"$($PSQL \"\")\"` to the bottom of the `student_info.sh` file, except with the correct query in it", "If you run your script, the last echo statement should print:\n```sh\n3.09\n```", "Practice the query in the psql prompt to make sure it's getting what you want", "You previously used `SELECT ROUND(AVG(major_id), 5) FROM students;` in the psql prompt", "Add `echo \"$($PSQL \"SELECT ROUND(AVG(gpa), 2) FROM students\")\"` to the bottom of the `student_info.sh` file" ] } ] }, { "id": "1950", "title": "./student_info.sh", "summary": "", "content": "", "steps": [ { "id": "1950.1", "setup": { "watchers": [ "../.bash_history" ], "commits": [ "078425db3d369c1e8f9b67203c25bb34dc38df5e" ] }, "content": "Run the script to see the average GPA of all your students.", "hints": [ "Run your `student_info.sh` script by executing it", "Type `./student_info.sh` in the terminal and press enter", "Make sure you are in the `project` folder first" ] } ] }, { "id": "1960", "title": "Add echo count of students per major with more than one student", "summary": "", "content": "", "steps": [ { "id": "1960.1", "setup": { "watchers": [ "./student_info.sh" ], "commits": [ "aea8661d39f4ba0a9d4355ba8fc143fe7e58e284" ] }, "content": "They're doing pretty good. Add another command to print `Major ID, total number of students in a column named 'number_of_students', and average GPA rounded to two decimal places in a column name 'average_gpa', for each major ID in the students table having a student count greater than 1:`", "hints": [ "At the bottom of the file, use `echo` with the `-e` flag and a new line character again to print the suggested sentence", "The new line character is `\\n`", "Here's an example of the command: `echo -e \"\\n\"`", "At the bottom of the `student_info.sh` file, add this:\n```sh\necho -e \"\\nMajor ID, total number of students in a column named 'number_of_students', and average GPA rounded to two decimal places in a column name 'average_gpa', for each major ID in the students table having a student count greater than 1:\"\n```" ] } ] }, { "id": "1970", "title": "psql SELECT COUNT(*) FROM majors", "summary": "", "content": "", "steps": [ { "id": "1970.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "8fd32452cc6410c7786ed2398934eee419edf486" ] }, "content": "Another function is `COUNT`. You can use it like this: `COUNT()`. It will tell you how many entries are in a table for the column. Try it out in the psql prompt by using `COUNT(*)` to see how many majors there are.", "hints": [ "Use the `SELECT`, `COUNT`, and `FROM` keywords", "Here's an example `SELECT COUNT() FROM
;`", "Use `*` for the column and `majors` for the table", "Enter `SELECT COUNT(*) FROM majors;` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "1980", "title": "psql SELECT COUNT(*) FROM students", "summary": "", "content": "", "steps": [ { "id": "1980.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "389d6f879917c88a45f5bb32aeb2c81c57891b8f" ] }, "content": "Using the same method, check how many students you have.", "hints": [ "You previously used: `SELECT COUNT(*) FROM majors;`", "Use the `SELECT`, `COUNT`, and `FROM` keywords", "Here's an example `SELECT COUNT() FROM
;`", "Use `*` for the column and `students` for the table", "Enter `SELECT COUNT(*) FROM students;` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "1990", "title": "psql SELECT COUNT(major_id) FROM students", "summary": "", "content": "", "steps": [ { "id": "1990.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "0867519f57248f32e096c830756e58e1ed04fd7b" ] }, "content": "Using `*` like that told you how many total rows are in the table. View the count of the `major_id` column in the `students` table to see how many of your students have picked a major.", "hints": [ "Use the `SELECT`, `COUNT`, and `FROM` keywords", "Here's an example `SELECT COUNT() FROM
;`", "Use `major_id` for the column and `students` for the table", "Enter `SELECT COUNT(major_id) FROM students;` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "2000", "title": "psql SELECT DISTINCT(major_id) FROM students", "summary": "", "content": "", "steps": [ { "id": "2000.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "18e52818f7cc649be240e94080f935dcc9e248ea" ] }, "content": "Using `major_id` didn't count the `null` values in that column. 23 students have a major. `DISTINCT` is a function that will show you only unique values. You can use it like this: `DISTINCT()`. View the unique `major_id` values in the `students` table.", "hints": [ "Use the `SELECT`, `COUNT`, and `FROM` keywords", "Here's an example `SELECT DISTINCT() FROM
;`", "Use `major_id` for the column and `students` for the table", "Enter `SELECT DISTINCT(major_id) FROM students;` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "2010", "title": "psql SELECT FROM students GROUP BY major_id", "summary": "", "content": "", "steps": [ { "id": "2010.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "1c5219b57cbe447c3e0d9d578f7109cc6b9b2eeb" ] }, "content": "There's six unique `major_id` values in the `students` table. You can get the same results with `GROUP BY`. Here's an example of how to use it: `SELECT FROM
GROUP BY `. Use this method to view the unique `major_id` values in the `students` table again.", "hints": [ "You want to **select** and **group** the `major_id` column", "Use the `SELECT`, `FROM`, and `GROUP BY` keywords", "Here's an example `SELECT COUNT() FROM
;`", "Use `major_id` for the column and `students` for the table", "Enter `SELECT major_id FROM students GROUP BY major_id;` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "2020", "title": "psql SELECT major_id, count(*) FROM students GROUP BY major_id", "summary": "", "content": "", "steps": [ { "id": "2020.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "222234aafbb72793e31d002c7973217064f9d9d2" ] }, "content": "The output was the same as `DISTINCT`, but with `GROUP BY` you can add any of the aggregate functions (`MIN`, `MAX`, `COUNT`, etc) to it to find more information. For instance, if you wanted to see how many students were in each major you could use `SELECT COUNT(*) FROM students GROUP BY major_id`. View the `major_id` column **and** number of students in each `major_id`.", "hints": [ "You want to `SELECT` two columns, `major_id` and the `COUNT` of all (`*`) the rows", "Use the `SELECT`, `COUNT`, `FROM`, and `GROUP BY` keywords", "Here's an example `SELECT , COUNT() FROM
GROUP BY ;`", "Enter `SELECT major_id, COUNT(*) FROM students GROUP BY major_id;` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "2030", "title": "psql SELECT major_id, MIN(gpa) FROM students GROUP BY major_id", "summary": "", "content": "", "steps": [ { "id": "2030.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "1c6a93ff9101bb7b0c60c1f1bbfead9b003ebf1e" ] }, "content": "When using `GROUP BY`, any columns in the `SELECT` area must be included in the `GROUP BY` area. Other columns must be used with any of the aggregate functions (`MAX`, `AVG`, `COUNT`, etc). View the unique `major_id` values with `GROUP BY` again, but see what the lowest GPA is in each of them.", "hints": [ "The last query was `SELECT major_id, COUNT(*) FROM students GROUP BY major_id;`", "Use the `SELECT`, `MIN`, `FROM`, and `GROUP BY` keywords", "Here's an example `SELECT , MIN() FROM
GROUP BY ;`", "Enter `SELECT major_id, MIN(gpa) FROM students GROUP BY major_id;` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "2040", "title": "psql SELECT MIN(gpa), MAX(gpa) FROM students GROUP BY major_id", "summary": "", "content": "", "steps": [ { "id": "2040.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "f30c38dbdb735291cbc08b110720b25abfab2c93" ] }, "content": "Nice job. Enter the same query, but add a column that shows you the highest GPA in each major as well.", "hints": [ "The last query was: `SELECT major_id, MIN(gpa) FROM students GROUP BY major_id;`", "Use the `SELECT`, `MIN`, `MAX`, `FROM`, and `GROUP BY` keywords", "Enter `SELECT major_id, MIN(gpa), MAX(gpa) FROM students GROUP BY major_id;` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "2050", "title": "psql SELECT MIN(gpa), MAX(gpa) FROM students GROUP BY major_id HAVING MAX(gpa) = 4", "summary": "", "content": "", "steps": [ { "id": "2050.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "4315208cbbb0a9f4d91af6b77aa7359ce95322d1" ] }, "content": "Another option with `GROUP BY` is `HAVING`. You can add it at the end like this: `SELECT FROM
GROUP BY HAVING `. The condition must be an aggregate function with a test. An example to might be to use `HAVING COUNT(*) > 0` to only show what whatever column is grouped that have at least one row. Use `HAVING` to only show rows from the last query that have a maximum GPA of 4.0.", "hints": [ "The last query was: `SELECT major_id, MIN(gpa), MAX(gpa) FROM students GROUP BY major_id;`", "Use the `SELECT`, `MIN`, `MAX`, `FROM`, `GROUP BY`, and `HAVING` keywords", "Here's an example `SELECT , MIN(), MAX() FROM
GROUP BY HAVING ;`", "The condition you want is `HAVING MAX(gpa) = 4.0`", "Enter `SELECT major_id, MIN(gpa), MAX(gpa) FROM students GROUP BY major_id HAVING MAX(gpa) = 4.0;` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "2060", "title": "psql SELECT MIN(gpa) AS, MAX(gpa) FROM students GROUP BY major_id HAVING MAX(gpa) = 4", "summary": "", "content": "", "steps": [ { "id": "2060.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "4dfb0403715a26a596a16c5d8a54e1940f7e3242" ] }, "content": "Two of your majors have at least one student with a 4.0 GPA. Looking at the results, the column is named `min`. You can rename a column with `AS` like this: `SELECT AS ` Enter the same command, but rename the `min` column to `min_gpa`.", "hints": [ "The last query was: `SELECT major_id, MIN(gpa), MAX(gpa) FROM students GROUP BY major_id HAVING MAX(gpa) = 4.0;`", "Use the `SELECT`, `MIN`, `AS`, `FROM`, and `GROUP BY` keywords", "Rename the `MIN(gpa)` column like this: `MIN(gpa) AS min_gpa`", "Enter `SELECT major_id, MIN(gpa) AS min_gpa, MAX(gpa) FROM students GROUP BY major_id HAVING MAX(gpa) = 4.0;` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "2070", "title": "psql SELECT MIN(gpa) AS, MAX(gpa) AS FROM students GROUP BY major_id HAVING MAX(gpa) = 4", "summary": "", "content": "", "steps": [ { "id": "2070.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "2f6ee0be72c874fab0fcb77233dd5560182710e8" ] }, "content": "Now the column has a better name. Enter the same command, but rename the `max` column to `max_gpa` as well.", "hints": [ "The last query was: `SELECT major_id, MIN(gpa) AS min_gpa, MAX(gpa) FROM students GROUP BY major_id HAVING MAX(gpa) = 4.0;`", "Use the `SELECT`, `MIN`, `AS`, `FROM`, and `GROUP BY` keywords", "Rename the `MAX(gpa)` column like this: `MAX(gpa) AS max_gpa`", "Enter `SELECT major_id, MIN(gpa) AS min_gpa, MAX(gpa) AS max_gpa FROM students GROUP BY major_id HAVING MAX(gpa) = 4.0;` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "2075", "title": "psql - SELECT major_id, COUNT() AS number_of_students FROM students GROUP BY major_id", "summary": "", "content": "", "steps": [ { "id": "2075.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "81512cff4986e7cbfbfd8e5faf0a0d327ae5367f" ] }, "content": "That's more descriptive. View the `major_id` and number of students in each `major_id` in a column named `number_of_students`.", "hints": [ "Use the `SELECT`, `COUNT`, `AS`, `FROM`, and `GROUP BY` keywords", "Here's an example: `SELECT , COUNT(*) AS FROM
GROUP BY ;`", "You want to `COUNT(*) AS number_of_students` and `GROUP BY major_id`", "Enter `SELECT major_id, COUNT(*) AS number_of_students FROM students GROUP BY major_id;` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "2080", "title": "psql SELECT COUNT(*) AS FROM students GROUP BY major_id HAVING COUNT(*) < 8", "summary": "", "content": "", "steps": [ { "id": "2080.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "fcdb91d06b8035b8982a126612ffd08928b554f7" ] }, "content": "Use `HAVING` with the last query to only show the rows with less than eight students in the major.", "hints": [ "The last query was: `SELECT major_id, COUNT(*) AS number_of_students FROM students GROUP BY major_id;`", "Here's an example: `SELECT , COUNT(*) AS FROM
GROUP BY HAVING ;`", "The condition you want is `COUNT(*) < 8`", "Enter `SELECT major_id, COUNT(*) AS number_of_students FROM students GROUP BY major_id HAVING COUNT(*) < 8;` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "2090", "title": "Add echo query result", "summary": "", "content": "", "steps": [ { "id": "2090.1", "setup": { "watchers": [ "./student_info.sh" ], "commits": [ "4795bae59a62c4ee64c38f970d5a112f4fd9001d" ] }, "content": "Well done. Back in your script, add the command the print the suggested results.", "hints": [ "Add `echo \"$($PSQL \"\")\"` to the bottom of the `student_info.sh` file, except with the correct query in it", "If you run your script, the last echo statement should print:\n```sh\n|8|2.97\n37|6|3.38\n36|6|2.92\n41|6|3.53\n38|4|2.73\n```", "Practice the query in the psql prompt to make sure it's getting what you want", "You previously used `SELECT major_id, COUNT(*) AS number_of_students FROM students GROUP BY major_id HAVING COUNT(*) < 8;` in the psql prompt", "Add `echo \"$($PSQL \"SELECT major_id, COUNT(*) AS number_of_students, ROUND(AVG(gpa),2) AS average_gpa FROM students GROUP BY major_id HAVING COUNT(*) > 1\")\"` to the bottom of the `student_info.sh` file" ] } ] }, { "id": "2100", "title": "./student_info.sh", "summary": "", "content": "", "steps": [ { "id": "2100.1", "setup": { "watchers": [ "../.bash_history" ], "commits": [ "9fb9c9dc854ee85a193e989e6ad1e89513d6f9e2" ] }, "content": "Run the script to see the output.", "hints": [ "Run your `student_info.sh` script by executing it", "Type `./student_info.sh` in the terminal and press enter", "Make sure you are in the `project` folder first" ] } ] }, { "id": "2110", "title": "Add echo majors with no students or student with ma", "summary": "", "content": "", "steps": [ { "id": "2110.1", "setup": { "watchers": [ "./student_info.sh" ], "commits": [ "bb2cc18702a5714493961a83df6ce3ff213a1f91" ] }, "content": "Add an echo command to your script like the others that prints `List of majors, in alphabetical order, that either no student is taking or has a student whose first name contains a case insensitive 'ma':`", "hints": [ "At the bottom of the file, use `echo` with the `-e` flag and a new line character again to print the suggested sentence", "The new line character is `\\n`", "Here's an example of the command: `echo -e \"\\n\"`", "At the bottom of the `student_info.sh` file, add this:\n```sh\necho -e \"\\nList of majors, in alphabetical order, that either no student is taking or has a student whose first name contains a case insensitive 'ma':\"\n```" ] } ] }, { "id": "2120", "title": "psql students FULL JOIN majors", "summary": "", "content": "", "steps": [ { "id": "2120.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "78059a95c721392c3d9043cc9607ab7f60ac2185" ] }, "content": "The `majors` and `students` table are linked with the `major_id` foreign key. If you want to see the name of a major that a student is taking, you need to `JOIN` the two tables into one. Here's an example of how to do that:\n`SELECT * FROM FULL JOIN ON . = .;`\n\nIn the psql prompt, join the two tables together with the above method.", "hints": [ "Join the `students` and `majors` table with the method in the example. Use the `students` table first where applicable", "Enter `SELECT * FROM students FULL JOIN majors ON students.major_id = majors.major_id;` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "2130", "title": "psql students LEFT JOIN majors", "summary": "", "content": "", "steps": [ { "id": "2130.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "24cfb24814d62d90a0fdcbd0cef122f2eebb1093" ] }, "content": "It's showing all the columns from both tables, the two `major_id` columns are the same in each row for the ones that have it. You can see that there are some students without a major, and some majors without any students. The `FULL JOIN` you used will include **all** rows from both tables, whether or not they have a row using that foreign key in the other. From there, you could use any of the previous methods to narrow down, group, order, etc. Use a `LEFT JOIN` to join the same two tables in the same way.", "hints": [ "Join the `students` and `majors` table with a `LEFT JOIN`. Use the `students` table first where applicable", "You previously entered: `SELECT * FROM students FULL JOIN majors ON students.major_id = majors.major_id;`", "Replace `FULL JOIN` from the previous command with `LEFT JOIN`", "Enter `SELECT * FROM students LEFT JOIN majors ON students.major_id = majors.major_id;` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "2140", "title": "psql students RIGHT JOIN majors", "summary": "", "content": "", "steps": [ { "id": "2140.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "df30052b829c23887e7712287a4bd3cd2f3df6df" ] }, "content": "There's a few less rows than the last query. In the `LEFT JOIN` you used, the `students` table was the left table since it was on the left side of the `JOIN`. `majors` was the right table. A `LEFT JOIN` gets all rows from the left table, but only rows from the right table that are linked to from the left one. Looking at the data, you can see that every student was returned, but the majors without any students were not. Join the same two tables with a `RIGHT JOIN` this time.", "hints": [ "Join the `students` and `majors` table with a `RIGHT JOIN`. Use the `students` table first where applicable", "You previously entered: `SELECT * FROM students LEFT JOIN majors ON students.major_id = majors.major_id;`", "Replace `LEFT JOIN` from the previous command with `RIGHT JOIN`", "Enter `SELECT * FROM students RIGHT JOIN majors ON students.major_id = majors.major_id;` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "2150", "title": "psql students INNER JOIN majors", "summary": "", "content": "", "steps": [ { "id": "2150.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "683dc7ec81e72d7b9a3151c4fb6877eddb0bcd7a" ] }, "content": "The right join showed all the rows from the right table (`majors`), but only rows from the left table (`students`) if they have a major. There's one more type you should know about. Join the two tables with an `INNER JOIN`.", "hints": [ "Join the `students` and `majors` table with an `INNER JOIN`. Use the `students` table first where applicable", "You previously entered: `SELECT * FROM students RIGHT JOIN majors ON students.major_id = majors.major_id;`", "Replace `RIGHT JOIN` from the previous command with `INNER JOIN`", "Enter `SELECT * FROM students INNER JOIN majors ON students.major_id = majors.major_id;` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "2160", "title": "psql majors LEFT JOIN students", "summary": "", "content": "", "steps": [ { "id": "2160.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "b998c90c1408ef9b3f584632a89771e09458a733" ] }, "content": "The `INNER JOIN` only returned students if they have a major and majors that have a student. In other words, it only returned rows if they have a value in the foreign key column (`major_id`) of the opposite table. You should know a little about the four main types of joins now. Try using a `LEFT JOIN` to show **all the majors** but only students that have a major.", "hints": [ "You want to join the `students` and `majors` tables again", "The left table is the on the left side of `LEFT JOIN`.", "A `LEFT JOIN` will show all rows from the left table.", "You previously entered: `SELECT * FROM students INNER JOIN majors ON students.major_id = majors.major_id;`", "Enter `SELECT * FROM majors LEFT JOIN students ON majors.major_id = students.major_id;` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "2170", "title": "psql majors INNER JOIN students", "summary": "", "content": "", "steps": [ { "id": "2170.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "561ed8f2d284cd249cab98a4b569e8aa296b0330" ] }, "content": "Excellent. All the majors are there. Next, use the appropriate join to show only students that are enrolled in a major, and only majors that have a student enrolled in it.", "hints": [ "You want to join the `students` and `majors` tables again", "Join them with the join that only shows rows if they have a value in the foreign key column of the other table", "The types of joins you learned are `FULL JOIN`, `LEFT JOIN`, `RIGHT JOIN`, and `INNER JOIN`", "The previous query was: `SELECT * FROM majors RIGHT JOIN students ON majors.major_id = students.major_id;`", "You want to use an `INNER JOIN` with the two tables", "Enter `SELECT * FROM majors INNER JOIN students ON majors.major_id = students.major_id;` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "2180", "title": "psql majors RIGHT JOIN students", "summary": "", "content": "", "steps": [ { "id": "2180.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "c4fe75e6d2caed029776a297f771f49e3cabf9a8" ] }, "content": ":thumbsup: Try using a right join to show all students but only majors if a student is enrolled in it.", "hints": [ "You want to join the `students` and `majors` tables again", "The left table is the on the left side of `RIGHT JOIN`.", "A `RIGHT JOIN` will show all rows from the right table.", "You previously entered: `SELECT * FROM students INNER JOIN majors ON students.major_id = majors.major_id;`", "Enter `SELECT * FROM majors RIGHT JOIN students ON majors.major_id = students.major_id;` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "2190", "title": "psql majors FULL JOIN students", "summary": "", "content": "", "steps": [ { "id": "2190.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "eb8a38e8e62f77f9b844b0bc69326281c2be0ce1" ] }, "content": "That showed all the students since it was the right table of the `RIGHT JOIN`. Use the appropriate join with the same two table to show all rows in both tables whether they have a value in the foreign key column or not.", "hints": [ "You want to join the `students` and `majors` tables again", "Join them with the join that only shows rows if they have a value in the foreign key column of the other table", "The previous query was: `SELECT * FROM majors INNER JOIN students ON majors.major_id = students.major_id;`", "You want to use an `INNER JOIN` with the two tables", "Enter `SELECT * FROM majors FULL JOIN students ON majors.major_id = students.major_id;` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "2200", "title": "psql SELECT * students INNER JOIN majors", "summary": "", "content": "", "steps": [ { "id": "2200.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "31f10041dbd68f18e51f545391cc098bda5cc79e" ] }, "content": "Lets do some more experiments with joins. Say you wanted to find a list of majors that students are taking. Use the most efficient `JOIN` to join the two tables you need. Only join the tables for now, don't use any other conditions.", "hints": [ "You want to join the `students` and `majors` tables again", "Use the join that shows you only students that have a major and only majors that have a student.", "Only use the join, don't use a `WHERE`, `HAVING`, or any other filters", "You previously used: `SELECT * FROM students FULL JOIN majors ON students.major_id = majors.major_id;`", "You want to use an `INNER JOIN`", "Enter `SELECT * FROM students INNER JOIN majors ON students.major_id = majors.major_id;` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "2210", "title": "psql SELECT major students INNER JOIN majors", "summary": "", "content": "", "steps": [ { "id": "2210.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "6881d69b3978ed745b19996b55e473d7f92acb0f" ] }, "content": "Good. To get the list, you don't need all the columns, though. Enter the same command, but just get the column you need.", "hints": [ "The previous query was `SELECT * FROM students INNER JOIN majors ON students.major_id = majors.major_id;`", "Enter the previous query, but only get the column you need", "You only need the `major` column", "Enter `SELECT major FROM students INNER JOIN majors ON students.major_id = majors.major_id;` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "2220", "title": "psql SELECT DISTINCT(major) students INNER JOIN majors", "summary": "", "content": "", "steps": [ { "id": "2220.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "f5eeb1b74bad069d10490e36ce4090d310ccdd3f" ] }, "content": "You also don't want any duplicates. Use `DISTINCT` to only return the unique ones to see the list of majors who have students.", "hints": [ "The previous query was `SELECT major FROM students INNER JOIN majors ON students.major_id = majors.major_id;`", "Enter the previous query, but only get the `DISTINCT` majors", "Here's an example: `DISTINCT()`", "You want to change `major` from the previous query to `DISTINCT(major)`", "Enter `SELECT DISTINCT(major) FROM students INNER JOIN majors ON students.major_id = majors.major_id;` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "2230", "title": "psql SELECT * students RIGHT JOIN majors", "summary": "", "content": "", "steps": [ { "id": "2230.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "63dadf69d416f19607f696928f829c258220112a" ] }, "content": "There's your list of majors that students are taking :smile: Next, say you wanted a list of majors that students aren't taking. Use the most efficient `JOIN` to join the two tables you need. Only join the tables for now, don't use any other conditions.", "hints": [ "You want to join the `students` and `majors` tables again", "Use the join that shows you all majors, but only students that have a major", "Only use the join, don't use a `WHERE`, `HAVING`, or any other filters", "You previously used: `SELECT * FROM students FULL JOIN majors ON students.major_id = majors.major_id;`", "You want to use a `RIGHT JOIN` with the `majors` table on the right of it", "Enter `SELECT * FROM students RIGHT JOIN majors ON students.major_id = majors.major_id;` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "2240", "title": "psql SELECT * students RIGHT JOIN majors WHERE student_id IS NULL", "summary": "", "content": "", "steps": [ { "id": "2240.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "afde1e3c60a38c2c5f88351c5d502282bee9eabe" ] }, "content": "That got you all the majors, you can see the ones that don't have any students. Add a `WHERE` condition to only see the majors without students, use `student_id` in it's condition.", "hints": [ "The previous query was `SELECT * FROM students RIGHT JOIN majors ON students.major_id = majors.major_id;`", "Enter the previous query, but add a `WHERE ` at the end to only get the rows you need", "Use `IS NULL` with the condition", "The keywords you want are `SELECT`, `FROM`, `RIGHT JOIN`, `ON`, `WHERE` and `IS NULL`", "Use `student_id IS NULL` as the condition", "Enter `SELECT * FROM students RIGHT JOIN majors ON students.major_id = majors.major_id WHERE student_id IS NULL;` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "2245", "title": "psql SELECT major students RIGHT JOIN majors WHERE student_id IS NULL", "summary": "", "content": "", "steps": [ { "id": "2245.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "5f89850c3f282dcff888453ee5f66c6653468aa1" ] }, "content": "Now you only have the rows you need. Only get the columns you need with it to see the list of majors without students.", "hints": [ "The previous query was `SELECT * FROM students LEFT JOIN majors ON students.major_id = majors.major_id WHERE student_id IS NULL;`", "Enter the previous query, but only get the column you need", "The column you need is the `major` column", "Enter `SELECT major FROM students RIGHT JOIN majors ON students.major_id = majors.major_id WHERE student_id IS NULL;` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "2250", "title": "psql SELECT * students LEFT JOIN majors", "summary": "", "content": "", "steps": [ { "id": "2250.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "0301ac06fc0dfee9112d49fff314c7edddd885c3" ] }, "content": "You're doing great. Next, use the most efficient 'JOIN' to join the tables you would need if you were asked to get the first name, last name, major, and GPA of students who are taking Data Science or have a gpa of 3.8 or greater. Only join the tables for now, don't use any other conditions.", "hints": [ "Use the join to get all students but only majors that have a student", "Only use the join, don't use a `WHERE`, `HAVING`, or any other conditional expressions.", "You previously used: `SELECT * FROM students RIGHT JOIN majors ON students.major_id = majors.major_id;`", "You want to use a `LEFT JOIN` with `students` as the left table", "Enter `SELECT * FROM students LEFT JOIN majors ON students.major_id = majors.major_id;` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "2260", "title": "psql SELECT students LEFT JOIN majors WHERE major = Data Science OR gpa >= 3.8", "summary": "", "content": "", "steps": [ { "id": "2260.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "735d429ec61b40507638fa3c129dc95cf4c22ca6" ] }, "content": "Enter the same command, but use `WHERE` to only get the students that meet the requirements. As a reminder, the goal was to find students who are taking Data Science or have a gpa of 3.8 or greater.", "hints": [ "The previous query was `SELECT * FROM students LEFT JOIN majors ON students.major_id = majors.major_id;`", "You want to add two conditions one testing the `major` column, and another testing the `gpa` column", "Here's an example `SELECT * FROM LEFT JOIN ON . = . WHERE OR ;`", "The two conditions you want are `major = 'Data Science'` and `gpa >= 3.8`", "Enter `SELECT * FROM students LEFT JOIN majors ON students.major_id = majors.major_id WHERE major='Data Science' OR gpa >= 3.8;` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "2265", "title": "psql SELECT columns LEFT JOIN WHERE major = Data Science OR gpa >= 3.8", "summary": "", "content": "", "steps": [ { "id": "2265.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "f3ba732355de435b94f98c6ac3c1ae0b5e642ca4" ] }, "content": "Now, you have narrowed it down the rows you are looking for. Enter the same command, but only get the columns you need. There was four of them, the students first name, last name, their major, and GPA. Get them in that order.", "hints": [ "The previous query was `SELECT * FROM students LEFT JOIN majors ON students.major_id = majors.major_id WHERE major='Data Science' OR gpa >= 3.8;`", "Enter the previous query, but only get the columns you need", "Get the `first_name`, `last_name`, `major`, and `gpa` columns in that order", "Enter `SELECT first_name, last_name, major, gpa FROM students LEFT JOIN majors ON students.major_id = majors.major_id WHERE major='Data Science' OR gpa >= 3.8;` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "2270", "title": "psql SELECT * students FULL JOIN majors", "summary": "", "content": "", "steps": [ { "id": "2270.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "58642c012b5b7a62f9850ed717133d489e9dd397" ] }, "content": "From there, you could put them in a specific order if you wanted or limit the results to a certain number among other things. Lastly, use the most efficient 'JOIN' to join the tables you would need if you were asked to get the first name and major for students whose `first_name`, or the `major`, contains `ri`. Only join the tables for now, don't use any other conditions.", "hints": [ "Use the join that gets all students and majors", "You previously used: `SELECT * FROM students LEFT JOIN majors ON students.major_id = majors.major_id;`", "You want to use a `FULL JOIN`", "Enter `SELECT * FROM students FULL JOIN majors ON students.major_id = majors.major_id;` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "2280", "title": "psql SELECT * students FULL JOIN majors WHERE first_name || major LIKE ri", "summary": "", "content": "", "steps": [ { "id": "2280.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "b40970bc421136f58604dd836578b5668a381558" ] }, "content": "Add a `WHERE` to the previous query so you only get the rows you need. The rows you wanted were the ones with a first name or major containing `ri`.", "hints": [ "The previous query was `SELECT * FROM students FULL JOIN majors ON students.major_id = majors.major_id;`", "You want to add two conditions one testing the `first_name` column, and another testing the `major` column", "Here's an example `SELECT * FROM LEFT JOIN ON . = . WHERE OR ;`", "The two conditions you want should use the `LIKE` or `ILIKE` keywords", "They conditions are `WHERE first_name LIKE '%ri%' OR major LIKE '%ri%'`", "Enter `SELECT * FROM students FULL JOIN majors ON students.major_id = majors.major_id WHERE first_name LIKE '%ri%' OR major LIKE '%ri%';` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "2290", "title": "psql SELECT major FROM students FULL JOIN majors WHERE WHERE first_name || major LIKE ri", "summary": "", "content": "", "steps": [ { "id": "2290.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "7156f0a6541b91cced351797b7d2ba685a70e8ac" ] }, "content": "Finally, you only wanted to display the `first_name` and `major` columns. Enter the previous query, but only get the columns you need.", "hints": [ "The previous query was `SELECT * FROM students LEFT JOIN majors ON students.major_id = majors.major_id WHERE first_name LIKE '%ri%' OR major LIKE '%ri%';`", "The two columns you want are `first_name` and `major`", "Enter `SELECT first_name, major FROM students FULL JOIN majors ON students.major_id = majors.major_id WHERE first_name LIKE '%ri%' OR major LIKE '%ri%';` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "2310", "title": "Add echo query result", "summary": "", "content": "", "steps": [ { "id": "2310.1", "setup": { "watchers": [ "./student_info.sh" ], "commits": [ "6964edefc66e1807268f7bb3da31c8aedb42f61f" ] }, "content": "In your script, add the command to print what the sentence is asking for.", "hints": [ "Add `echo \"$($PSQL \"\")\"` to the bottom of the `student_info.sh` file, except with the correct query in it", "If you run your script, the last echo statement should print:\n```sh\nComputer Programming\nDatabase Administration\nNetwork Engineering\nWeb Development\n```", "Practice the query in the psql prompt to make sure it's getting what you want", "You previously used `SELECT first_name, major FROM students FULL JOIN majors ON students.major_id = majors.major_id WHERE first_name LIKE '%ri%' OR major LIKE '%ri%';` in the psql prompt", "Add `echo \"$($PSQL \"SELECT major FROM students FULL JOIN majors ON students.major_id = majors.major_id WHERE major IS NOT NULL AND (student_id IS NULL OR first_name ILIKE '%ma%') ORDER BY major\")\"` to the bottom of the `student_info.sh` file" ] } ] }, { "id": "2320", "title": "./student_info.sh", "summary": "", "content": "", "steps": [ { "id": "2320.1", "setup": { "watchers": [ "../.bash_history" ], "commits": [ "af42cdfa9d583dbeb60018b5f137ff2a4828d583" ] }, "content": "Run the script to see the majors described.", "hints": [ "Run your `student_info.sh` script by executing it", "Type `./student_info.sh` in the terminal and press enter", "Make sure you are in the `project` folder first" ] } ] }, { "id": "2330", "title": "Add echo courses with no students or Obie Hilpert", "summary": "", "content": "", "steps": [ { "id": "2330.1", "setup": { "watchers": [ "./student_info.sh" ], "commits": [ "ee79e2913a9e8df59d0e203fe4824f632af3bd0c" ] }, "content": ":smile: Almost done. In your script, add a command to print this sentence like the others: `List of unique courses, in reverse alphabetical order, that no student or 'Obie Hilpert' is taking:`", "hints": [ "At the bottom of the file, use `echo` with the `-e` flag and a new line character again to print the suggested sentence", "The new line character is `\\n`", "Here's an example of the command: `echo -e \"\\n\"`", "At the bottom of the `student_info.sh` file, add this:\n```sh\necho -e \"\\nList of unique courses, in reverse alphabetical order, that no student or 'Obie Hilpert' is taking:\"\n```" ] } ] }, { "id": "2340", "title": "psql SELECT * FROM students FULL JOIN majors", "summary": "", "content": "", "steps": [ { "id": "2340.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "5c4644d410178dbbc49f2fffb09e7e64965af28a" ] }, "content": "Lets go over a few more things before you figure out how to see the courses a student is taking. Start by doing a `FULL JOIN` on your `students` and `majors` tables.", "hints": [ "Join the `students` and `majors` table with a `FULL JOIN`. Use the `students` table first where applicable", "Enter `SELECT * FROM students FULL JOIN majors ON students.major_id = majors.major_id;` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "2350", "title": "psql SELECT students.major_id students FULL JOIN majors", "summary": "", "content": "", "steps": [ { "id": "2350.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "98fa85b9f08b93b1298fba6f5a4e3c2c6e335322" ] }, "content": "If you look at the column names, it shows two `major_id` columns. One from the `students` table and one from the `majors` table. If you were to try and query it using `major_id`, you would get an error. You would need to specify what table you want the column from like this: `
.`. Enter the same join but only get the `major_id` column from the `students` table.", "hints": [ "The previous query was `SELECT * FROM students FULL JOIN majors ON students.major_id = majors.major_id;`", "You can get the column you want with `students.major_id`", "Enter `SELECT students.major_id FROM students FULL JOIN majors ON students.major_id = majors.major_id;` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "2360", "title": "psql SELECT students.major_id FROM students FULL JOIN majors AS m", "summary": "", "content": "", "steps": [ { "id": "2360.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "dd38f2c6d5e7fc09f82cae43904016df94f77c8a" ] }, "content": "Earlier, you used `AS` to rename columns. You can use it to rename tables, or give them aliases, as well. Here's an example: `SELECT * FROM
AS ;`. Enter the same query you just entered, but rename the `majors` table to `m`. Anywhere the `majors` table is referenced, you will need to use `m` instead of `majors`.", "hints": [ "The previous query was `SELECT students.major_id FROM students FULL JOIN majors ON students.major_id = majors.major_id;`", "You want to join `majors AS m` and use `m.major_id` when referencing the joining column", "Enter `SELECT students.major_id FROM students FULL JOIN majors AS m ON students.major_id = m.major_id;` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "2370", "title": "psql SELECT s.major_id FROM students AS s FULL JOIN majors AS m", "summary": "", "content": "", "steps": [ { "id": "2370.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "acfc4d2fef2a0e0528b1af1457d998d9c5c43ad7" ] }, "content": "This doesn't affect the output. It can just make some queries easier to read. Enter the same query, but rename the `students` table to `s` as well.", "hints": [ "The previous query was `SELECT students.major_id FROM students FULL JOIN majors AS m ON students.major_id = m.major_id;`", "You want to rename `students AS s` and use `s.` when referencing columns from the `students` table", "Enter `SELECT s.major_id FROM students AS s FULL JOIN majors AS m ON s.major_id = m.major_id;` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "2390", "title": "psql SELECT * FROM students FULL JOIN majors USING", "summary": "", "content": "", "steps": [ { "id": "2390.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "086e25a697fa2b0d41fd32eaa454efe8506f57e8" ] }, "content": "There's a shortcut keyword, `USING` to join tables if the foreign key column has the same name in both tables. Here's an example: `SELECT * FROM FULL JOIN USING();`. Use this method to see **all** the columns in the `students` and `majors` table. Don't use any aliases.", "hints": [ "Enter `SELECT * FROM students FULL JOIN majors USING(major_id);` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "2400", "title": "psql SELECT * FROM students FULL JOIN majors USING FULL JOIN major_courses USING", "summary": "", "content": "", "steps": [ { "id": "2400.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "8f7704903c3e5376cc1763d7982054748961d3d3" ] }, "content": "Note that the two `major_id` columns were turned into one with `USING`. In order to find out what courses a student is taking, you will need to join all the tables together. You can add a third table to a join like this: `SELECT * FROM FULL JOIN USING() FULL JOIN USING()`. This example will join the first two tables into one, turning it into the left table for the second join. Use this method to join the two tables from the previous query with the `majors_courses` table.", "hints": [ "The previous query was `SELECT * FROM students FULL JOIN majors USING(major_id);`", "View the details of the `majors_courses` table with `\\d majors_courses` to find the foreign key to join on", "It's the `major_id` column", "Enter `SELECT * FROM students FULL JOIN majors USING(major_id) FULL JOIN majors_courses USING(major_id);` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "2410", "title": "psql SELECT * students FULL JOIN majors USING JOIN major_courses USING JOIN courses USING", "summary": "", "content": "", "steps": [ { "id": "2410.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "640ba48cde45129ff1cc95bb390da608b262569e" ] }, "content": "You may need to adjust the terminal size to align the output. What you're seeing is every unique combination of rows in the database. Students with a major are listed multiple times, one for each course included in the major. The majors without any students are there along with the courses for them. The students without a major are included, they have no courses and are only listed once. You can join as many tables together as you want. Join the last table to the previous command to get the names of the courses with all this info.", "hints": [ "The previous query was `SELECT * FROM students FULL JOIN majors USING(major_id) FULL JOIN majors_courses USING(major_id);`", "The last table is the `courses` table", "View the details of the `courses` table with `\\d courses` to find the foreign key to join on", "Enter `SELECT * FROM students FULL JOIN majors USING(major_id) FULL JOIN majors_courses USING(major_id) FULL JOIN courses USING(course_id);` in the psql prompt", "Enter `psql --username=freecodecamp --dbname=students` in the terminal to log into the psql prompt if you aren't already" ] } ] }, { "id": "2420", "title": "Add echo query result", "summary": "", "content": "", "steps": [ { "id": "2420.1", "setup": { "watchers": [ "./student_info.sh" ], "commits": [ "721bb6ee05bbe00deb22ee8802b488292c1d9c2d" ] }, "content": "Same amount of rows, but you get the course names now. In your script, add the command to print the suggested info.", "hints": [ "Add `echo \"$($PSQL \"\")\"` to the bottom of the `student_info.sh` file, except with the correct query in it", "If you run your script, the last echo statement should print:\n```sh\nWeb Programming\nWeb Applications\nPython\nObject-Oriented Programming\nNetwork Security\nData Structures and Algorithms\nComputer Systems\nComputer Networks\nAlgorithms\n```", "Practice the query in the psql prompt to make sure it's getting what you want", "You previously used `SELECT * FROM students FULL JOIN majors USING(major_id) FULL JOIN majors_courses USING(major_id) FULL JOIN courses USING(course_id);` in the psql prompt", "Add `echo \"$($PSQL \"SELECT DISTINCT(course) FROM students RIGHT JOIN majors USING(major_id) INNER JOIN majors_courses USING(major_id) INNER JOIN courses USING(course_id) WHERE (first_name = 'Obie' AND last_name = 'Hilpert') OR student_id IS NULL ORDER BY course DESC\")\"` to the bottom of the `student_info.sh` file" ] } ] }, { "id": "2430", "title": "./student_info.sh", "summary": "", "content": "", "steps": [ { "id": "2430.1", "setup": { "watchers": [ "../.bash_history" ], "commits": [ "5c0474486e3f99926f3af822c84b25291380bcaa" ] }, "content": "Run the script to see courses described.", "hints": [ "Run your `student_info.sh` script by executing it", "Type `./student_info.sh` in the terminal and press enter", "Make sure you are in the `project` folder first" ] } ] }, { "id": "2440", "title": "Add echo courses with only one student", "summary": "", "content": "", "steps": [ { "id": "2440.1", "setup": { "watchers": [ "./student_info.sh" ], "commits": [ "ee199454a8befbd98acd5486f09dedb758dce6c1" ] }, "content": "Last one. Add a command that prints `List of courses, in alphabetical order, with only one student enrolled:`.", "hints": [ "At the bottom of the file, use `echo` with the `-e` flag and a new line character again to print the suggested sentence", "The new line character is `\\n`", "Here's an example of the command: `echo -e \"\\n\"`", "At the bottom of the `student_info.sh` file, add this:\n```sh\necho -e \"\\nList of courses, in alphabetical order, with only one student enrolled:\"\n```" ] } ] }, { "id": "2450", "title": "Add echo query result", "summary": "", "content": "", "steps": [ { "id": "2450.1", "setup": { "watchers": [ "./student_info.sh" ], "commits": [ "7fd5773ba45d54adff5db90699905eb03aaa5b60" ] }, "content": "Go for it.", "hints": [ "Add a command at the bottom of the script to print the suggested information", "Add `echo \"$($PSQL \"\")\"` to the bottom of the `student_info.sh` file, except with the correct query in it", "If you run your script, the last echo statement should print:\n```sh\nComputer Networks\nComputer Systems\nServer Administration\nUNIX\n```", "Practice the query in the psql prompt to make sure it's getting what you want", "You can do this", "Give it another try", "I don't know how to get it either", "So there's no answers here", ":confused:", "Try entering this in the psql prompt: `SELECT COUNT(course), COURSE FROM students INNER JOIN majors USING(major_id) INNER JOIN majors_courses USING(major_id) INNER JOIN courses USING(course_id) GROUP BY course;`", "Add `echo \"$($PSQL \"SELECT course FROM students INNER JOIN majors_courses USING(major_id) INNER JOIN courses USING(course_id) GROUP BY course HAVING COUNT(student_id) = 1 ORDER BY course\")\"` to the bottom of the `student_info.sh` file" ] } ] }, { "id": "2460", "title": "./student_info.sh", "summary": "", "content": "", "steps": [ { "id": "2460.1", "setup": { "watchers": [ "../.bash_history" ], "commits": [ "71f70146bdc31fc314b9f4a3b143e33067d31e6f" ] }, "content": "This is the last step, you have done really well. Run the script one last time. :wave:", "hints": [ "Run your `student_info.sh` script by executing it", "Type `./student_info.sh` in the terminal and press enter", "Make sure you are in the `project` folder first" ] } ] } ] }