├── .gitignore ├── README.md ├── docker-compose.yaml └── source_data ├── csv └── stephen_king_books.csv ├── images ├── plain_text_vs_highlighting.PNG └── rendered_markdown.PNG └── sql_scripts ├── sql_portfolio_tutorial.sql └── sql_portfolio_tutorial_no_extension /.gitignore: -------------------------------------------------------------------------------- 1 | /db/pgdata 2 | ./vscode -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## SQL Portfolio Tutorial 2 | 3 | **Author**: Jaime M. Shaker
4 | **Email**: jaime.m.shaker@gmail.com
5 | **Website**: https://www.shaker.dev
6 | **LinkedIn**: https://www.linkedin.com/in/jaime-shaker/
7 | 8 | ### How to create an SQL/Data Analytics portfolio on Github 9 | 10 | A simple, one page tutorial on how to use the Markdown language to showcase your SQL/Data Analytics portfolio on Github. 11 | 12 | :exclamation: If you find this repository helpful, please consider giving it a :star:. Thanks! :exclamation: 13 | 14 | #### How can I have my SQL portfolio look like yours? 15 | 16 | A common request that I get is for assistance in making an SQL portfolio more professional looking that just plain SQL code in a file. I hope this short tutorial helps others with creating a better presentation for their Data Analytics/SQL projects. 17 | 18 | All of my SQL projects consist of at least two (2) separate files. 19 | - SQL File 20 | - Markdown File 21 | 22 | The SQL file is the file that consist of the actual SQL code. This should be pretty self-explanatory, but I do want to mention an important note. 23 | 24 | :exclamation: Make sure to give your SQL file an `.sql` extension! :exclamation: 25 | 26 | With a `.sql` extension your file will have syntax highlighting which will make it much easier to read and appear much more professional looking. 27 | 28 | Note the difference between the following two files. One file has the `.sql` extension, the other does not. 29 | 30 | - [sql_portfolio_sql.sql](./source_data/sql_scripts/sql_portfolio_tutorial.sql) 31 | - [sql_portfolio_sql_no_extension](./source_data/sql_scripts/sql_portfolio_tutorial_no_extension) 32 | 33 | Same exact code but the file extension changes how it is rendered by the browser. 34 | 35 | ![plaintext vs syntax highlighting](./source_data/images/plain_text_vs_highlighting.PNG) 36 | 37 | Other than the SQL file, I also include a presentation file written in the Markdown language. This very file that you are reading is a Markdown file as you can tell my the `.md` extension in the file name. 38 | 39 | Markdown is a lightweight markup language that you can use to add formatting elements to plaintext text documents. Markdown is similar but much simpler than HTML. 40 | 41 | Markdown can be learned in as little as 15 minutes. You can learn more about Markdown at the following links. 42 | 43 | - [Markdown Tutorial](https://www.markdowntutorial.com/) 44 | - [Markdown Guide](https://www.markdownguide.org/getting-started/) 45 | 46 | #### What about icons/emoji's? Can I also add them to my file to give it a little more style? Where can I find them? 47 | 48 | Sure, just use the [Github Emoji Picker](https://github-emoji-picker.rickstaa.dev/) or check out this [Github repository](https://gist.github.com/rxaviers/7360908). 49 | 50 | Although I would encourage you to use them sparingly. 51 | 52 | #### Is there an easy way to practice without having to download anything? 53 | 54 | You can practice using Markdown with an online, in-browser WYSIWYG editor. This will allow you to easily create a Markdown file and see the rendered results in real-time. 55 | 56 | [StackEdit.io](https://stackedit.io/) 57 | 58 | If you follow along with my [source code](https://raw.githubusercontent.com/iweld/sql_portfolio_tutorial/main/README.md?token=GHSAT0AAAAAACHE5256YAFERDD3WJZ3D3E4ZJCBUWA), it should not be too difficult to comprehend. Markdown is a very simple language to understand and implement. 59 | 60 | #### How can I get started? 61 | 62 | For this tutorial, I am using [PostgreSQL](https://www.postgresql.org/) within a [Docker](https://www.docker.com/get-started/) container to run the `.sql` scripts. If you would like to do the same but don't know how, you can follow this walkthrough and it will guide you on how to create a PostgreSQL container within Docker. Very useful information and not difficult but not necessary for this tutorial. 63 | 64 | [Docker/PostgreSQL Getting Started Guide](https://github.com/iweld/SQL_Coding_Challenge/blob/main/walkthrough/WALKTHROUGH_1_DOCKER.md) 65 | 66 | To access the PostgreSQL server, I use a Universal Database Manager named [DBeaver](https://dbeaver.io/). The community version of [DBeaver](https://dbeaver.io/) is completely **FREE**. 67 | 68 | [DBeaver](https://dbeaver.io/) 69 | 70 | This database manager works with **MANY** different types of Databases (PostgreSQL, MySQL, SQLite, Oracle...). With this software you can manage your databases, tables and run your SQL queries. Using DBeaver I can have the query results output as text. 71 | 72 | ```sql 73 | book_id|book_title |no_of_pages| 74 | -------|----------------------------------|-----------| 75 | 21|It | 1138| 76 | 55|Under The Dome | 1074| 77 | 27|Four Past Midnight | 930| 78 | 57|11/22/1963 | 849| 79 | 48|The Dark Tower VII: The Dark Tower| 845| 80 | ``` 81 | 82 | Using Markdown, I can easily convert the output into a tabular format. 83 | 84 | book_id|book_title |no_of_pages| 85 | -------|----------------------------------|-----------| 86 | 21|It | 1138| 87 | 55|Under The Dome | 1074| 88 | 27|Four Past Midnight | 930| 89 | 57|11/22/1963 | 849| 90 | 48|The Dark Tower VII: The Dark Tower| 845| 91 | 92 | To write the Markdown source code, I use [VSCode](https://code.visualstudio.com/). VSCode is **FREE** and one of the most popular lightweight IDE's in the tech space right now. 93 | 94 | [Visual Studio Code](https://code.visualstudio.com/) 95 | 96 | VSCode is not necessary to write Markdown. You can write Markdown with a simple text editor like Notepad.exe. However, within VSCode, I also use an extension called `Markdown Preview Enhanced` that allows me to see the rendered Markdown code in real time. 97 | 98 | ![vscode screenshot](./source_data/images/rendered_markdown.PNG) 99 | 100 | So within my Github repository, I will have a `my_queries.sql` file to show the actual SQL queries **AND** I will have a separate `my_queries.md` file to display the page in a cleaner format. 101 | 102 | Within Markdown, I can show the actual SQL (or any programming/scripting language) by enclosing the code within a code block like so... 103 | 104 | 105 | ````markdown 106 | ```sql 107 | SELECT DISTINCT 108 | column_name 109 | FROM 110 | some_table 111 | WHERE 112 | column_name IS NOT NULL; 113 | ``` 114 | ```` 115 | 116 | This will allow your SQL code (or any programming/scripting code for that matter) to be rendered with syntax highlighting and proper formatting like so... 117 | 118 | ```sql 119 | SELECT DISTINCT 120 | column_name 121 | FROM 122 | some_table 123 | WHERE 124 | column_name IS NOT NULL; 125 | ``` 126 | 127 | I have created a small [SQL file](./source_data/sql_scripts/sql_portfolio_tutorial.sql) to show a practical example on how this could be used. Follow the example below. 128 | 129 | #### Markdown File Example 130 | 131 | **1**. How many records are in our table? 132 | 133 | ```sql 134 | SELECT 135 | COUNT(*) AS book_count 136 | FROM 137 | stephen_king.books; 138 | ``` 139 | 140 | **Results**: 141 | 142 | book_count| 143 | ----------| 144 | 75| 145 | 146 | :exclamation: We can put either our query or the results inside the \
Your Code Here\
to hide the text until it is clicked. :exclamation: 147 | 148 |

149 | 150 | **2**. List the book id, capitalized title and number of pages from the top 5 books with greatest number of pages. 151 | 152 | **Expected Results**: 153 | 154 | book_id|book_title |no_of_pages| 155 | -------|----------------------------------|-----------| 156 | 21|It | 1138| 157 | 55|Under The Dome | 1074| 158 | 27|Four Past Midnight | 930| 159 | 57|11/22/1963 | 849| 160 | 48|The Dark Tower VII: The Dark Tower| 845| 161 | 162 |

163 | Click to expand the Answer! 164 | 165 | ##### Answer: 166 | 167 | ```sql 168 | SELECT 169 | book_id, 170 | INITCAP(book_title) AS book_title, 171 | no_of_pages 172 | FROM 173 | stephen_king.books 174 | ORDER BY 175 | no_of_pages DESC 176 | LIMIT 5; 177 | ``` 178 |
179 |

180 | 181 | **3**. List the amount of time (in years) that have passed since the first published book and the last published book. 182 | 183 | ```sql 184 | SELECT 185 | MIN(year_published) AS first_published, 186 | MAX(year_published) AS last_published, 187 | (MAX(year_published) - MIN(year_published)) AS years_passed 188 | FROM 189 | stephen_king.books; 190 | ``` 191 | 192 | **Results**: 193 | 194 | first_published|last_published|years_passed| 195 | ---------------|--------------|------------| 196 | 1974| 2022| 48| 197 | 198 | As you can see, You will have to copy the SQL code, the query results and then paste it onto the markdown file. 199 | 200 | This is some extra work, but I think it looks much better and it's a great way to showcase your technical abilities and attention to detail. 201 | 202 | I hope this helps you. Feel free to message me if you have any questions or want to show off your work! Good luck! 203 | 204 | :exclamation: If you find this repository helpful, please consider giving it a :star:. Thanks! :exclamation: 205 | -------------------------------------------------------------------------------- /docker-compose.yaml: -------------------------------------------------------------------------------- 1 | version: '3.8' 2 | services: 3 | postgres: 4 | image: postgres 5 | container_name: sql_portfolio_tutorial 6 | restart: unless-stopped 7 | #- .env 8 | environment: 9 | POSTGRES_DB: sql_portfolio_tutorial 10 | POSTGRES_USER: postgres 11 | POSTGRES_PASSWORD: postgres 12 | PGDATA: /var/lib/postgresql/data/pgdata 13 | ports: 14 | - "5432:5432" 15 | volumes: 16 | - 17 | type: bind 18 | source: ./db 19 | target: /var/lib/postgresql/data 20 | - 21 | type: bind 22 | source: ./source_data 23 | target: /var/lib/postgresql/source_data 24 | networks: 25 | - reference 26 | networks: 27 | reference: -------------------------------------------------------------------------------- /source_data/csv/stephen_king_books.csv: -------------------------------------------------------------------------------- 1 | book_id,book_title,year_published,book_type,author,no_of_pages,goodreads_number_of_ratings,goodreads_avg_rating 2 | 1,carrie,1974,novel,stephen king,199,639126,3.98 3 | 2,salems lot,1975,novel,stephen king,439,404379,4.05 4 | 3,rage,1976,novel,richard bachman,211,42253,3.75 5 | 4,the shining,1977,novel,stephen king,447,1346512,4.26 6 | 5,the stand,1978,novel,stephen king,823,707918,4.34 7 | 6,night shift,1978,collection,stephen king,409,167106,4.03 8 | 7,the long walk,1978,novel,richard bachman,384,158786,4.1 9 | 8,the dead zone,1979,novel,stephen king,428,207616,3.95 10 | 9,firestarter,1980,novel,stephen king,426,213338,3.91 11 | 10,roadwork,1981,novel,richard bachman,274,33970,3.6 12 | 11,cujo,1981,novel,stephen king,319,260864,3.76 13 | 12,the running man,1981,novel,richard bachman,219,119714,3.89 14 | 13,the dark tower: the gunslinger,1982,novel,stephen king,224,569399,3.93 15 | 14,different seasons,1982,collection,stephen king,560,193667,4.35 16 | 15,christine,1983,novel,stephen king,526,225127,3.82 17 | 16,pet sematary,1983,novel,stephen king,374,523296,4.04 18 | 17,cycle of the werewolf,1983,novel,stephen king,127,55707,3.66 19 | 18,the talisman,1984,novel,stephen king,646,120487,4.12 20 | 19,thinner,1984,novel,richard bachman,309,196211,3.76 21 | 20,skeleton crew,1985,collection,stephen king,612,119058,3.97 22 | 21,it,1986,novel,stephen king,1138,992330,4.25 23 | 22,the eyes of the dragon,1987,novel,stephen king,326,118415,3.94 24 | 23,the dark tower ii: the drawing of the three,1987,novel,stephen king,400,241703,4.23 25 | 24,misery,1987,novel,stephen king,310,614259,4.2 26 | 25,the tommyknockers,1987,novel,stephen king,558,141782,3.58 27 | 26,the dark half,1989,novel,stephen king,431,134857,3.8 28 | 27,four past midnight,1990,collection,stephen king,930,104483,3.94 29 | 28,the dark tower iii: the waste lands,1991,novel,stephen king,512,206126,4.24 30 | 29,needful things,1991,novel,stephen king,690,234118,3.95 31 | 30,geralds game,1992,novel,stephen king,352,150081,3.56 32 | 31,dolores claiborne,1992,novel,stephen king,305,141263,3.9 33 | 32,nightmares & dreamscapes,1993,collection,stephen king,836,79143,3.95 34 | 33,insomnia,1994,novel,stephen king,787,147258,3.83 35 | 34,rose madder,1995,novel,stephen king,420,106217,3.73 36 | 35,the green mile,1996,novel,stephen king,400,289929,4.46 37 | 36,desperation,1996,novel,stephen king,704,133303,3.84 38 | 37,the regulators,1996,novel,richard bachman,480,79231,3.72 39 | 38,the dark tower iv: wizard and glass,1997,novel,stephen king,787,184279,4.25 40 | 39,bag of bones,1998,novel,stephen king,529,188425,3.91 41 | 40,the girl who loved tom gordon,1999,novel,stephen king,224,149040,3.62 42 | 41,hearts in atlantis,1999,collection,stephen king,640,90728,4.05 43 | 42,dreamcatcher,2001,novel,stephen king,620,166258,3.65 44 | 43,black house,2001,novel,stephen king,625,59150,4.02 45 | 44,everythings eventual,2002,collection,stephen king,605,95207,3.97 46 | 45,from a buick 8,2002,novel,stephen king,368,65227,3.47 47 | 46,the dark tower v: wolves of the calla,2003,novel,stephen king,714,172022,4.19 48 | 47,the dark tower vi: song of susannah,2004,novel,stephen king,432,147310,3.99 49 | 48,the dark tower vii: the dark tower,2004,novel,stephen king,845,161541,4.27 50 | 49,the colorado kid,2005,novel,stephen king,184,45453,3.38 51 | 50,cell,2006,novel,stephen king,351,211931,3.66 52 | 51,liseys story,2006,novel,stephen king,528,80400,3.7 53 | 52,blaze,2007,novel,richard bachman,304,46314,3.75 54 | 53,duma key,2008,novel,stephen king,607,114287,3.96 55 | 54,just after sunset,2008,collection,stephen king,367,51529,3.87 56 | 55,under the dome,2009,novel,stephen king,1074,283229,3.91 57 | 56,"full dark, no stars",2010,collection,stephen king,368,103105,4.07 58 | 57,11/22/1963,2011,novel,stephen king,849,489810,4.32 59 | 58,the dark tower: the wind through the keyhole,2012,novel,stephen king,336,76153,4.15 60 | 59,joyland,2013,novel,stephen king,288,143049,3.93 61 | 60,doctor sleep,2013,novel,stephen king,531,235763,4.12 62 | 61,mr. mercedes,2014,novel,stephen king,436,282210,3.99 63 | 62,revival,2014,novel,stephen king,403,115043,3.8 64 | 63,finders keepers,2015,novel,stephen king,434,131830,4.05 65 | 64,the bazaar of bad dreams,2015,novel,stephen king,495,55623,3.92 66 | 65,end of watch,2016,novel,stephen king,496,106491,4.09 67 | 66,gwendys button box,2017,novel,stephen king,175,60226,3.92 68 | 67,sleeping beauties,2017,novel,stephen king,702,75757,3.73 69 | 68,the outsider,2018,novel,stephen king,576,254614,3.99 70 | 69,elevation,2018,novel,stephen king,144,110287,3.66 71 | 70,the institute,2019,novel,stephen king,576,218361,4.2 72 | 71,if it bleeds,2020,collection,stephen king,447,78844,4.01 73 | 72,later,2021,novel,stephen king,256,104029,3.97 74 | 73,billy summers,2021,novel,stephen king,528,113528,4.23 75 | 74,gwendy's final task,2022,novel,stephen king,412,11452,4.13 76 | 75,fairy tale,2022,novel,stephen king,599,69206,3.8 77 | -------------------------------------------------------------------------------- /source_data/images/plain_text_vs_highlighting.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iweld/sql_portfolio_tutorial/279ddff8909e29801add7f091974bdbfea1bdfe1/source_data/images/plain_text_vs_highlighting.PNG -------------------------------------------------------------------------------- /source_data/images/rendered_markdown.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iweld/sql_portfolio_tutorial/279ddff8909e29801add7f091974bdbfea1bdfe1/source_data/images/rendered_markdown.PNG -------------------------------------------------------------------------------- /source_data/sql_scripts/sql_portfolio_tutorial.sql: -------------------------------------------------------------------------------- 1 | /* 2 | SQL Portfolio Tutorial 3 | Author: Jaime M. Shaker 4 | Email: jaime.m.shaker@gmail.com or jaime@shaker.dev 5 | Website: https://www.shaker.dev 6 | LinkedIn: https://www.linkedin.com/in/jaime-shaker/ 7 | 8 | File Name: sql_portfolio_tutorial.sql 9 | 10 | This SQL file was created for the SQL Portfolio Tutorial as I try to show others how 11 | they can display their SQL portfolios on GitHub. 12 | 13 | */ 14 | 15 | /*********************************************** 16 | 17 | Create schema 18 | 19 | ***********************************************/ 20 | 21 | CREATE SCHEMA IF NOT EXISTS stephen_king; 22 | 23 | /*********************************************** 24 | 25 | Create Table 26 | 27 | ***********************************************/ 28 | 29 | DROP TABLE IF EXISTS stephen_king.books; 30 | CREATE TABLE stephen_king.books ( 31 | book_id INT, 32 | book_title TEXT, 33 | year_published INT, 34 | book_type TEXT, 35 | author TEXT, 36 | no_of_pages INT, 37 | goodreads_number_of_ratings INT, 38 | goodreads_avg_rating NUMERIC, 39 | PRIMARY KEY (book_id) 40 | ); 41 | 42 | /*********************************************** 43 | 44 | Copy data from CSV 45 | 46 | ***********************************************/ 47 | 48 | COPY stephen_king.books ( 49 | book_id, 50 | book_title, 51 | year_published, 52 | book_type, 53 | author, 54 | no_of_pages, 55 | goodreads_number_of_ratings, 56 | goodreads_avg_rating 57 | ) 58 | FROM '/var/lib/postgresql/source_data/csv/stephen_king_books.csv' 59 | WITH DELIMITER ',' HEADER CSV; 60 | 61 | /*********************************************** 62 | 63 | Simple Queries 64 | 65 | ***********************************************/ 66 | 67 | -- 1. How many records are in our table? 68 | 69 | SELECT 70 | COUNT(*) AS book_count 71 | FROM 72 | stephen_king.books; 73 | 74 | /* 75 | 76 | book_count| 77 | ----------+ 78 | 75| 79 | 80 | */ 81 | 82 | -- 2. List the book id, capitalized title and number of pages from the top 5 books with greatest number of pages. 83 | 84 | SELECT 85 | book_id, 86 | INITCAP(book_title) AS book_title, 87 | no_of_pages 88 | FROM 89 | stephen_king.books 90 | ORDER BY 91 | no_of_pages DESC 92 | LIMIT 5; 93 | 94 | /* 95 | 96 | book_id|book_title |no_of_pages| 97 | -------+----------------------------------+-----------+ 98 | 21|It | 1138| 99 | 55|Under The Dome | 1074| 100 | 27|Four Past Midnight | 930| 101 | 57|11/22/1963 | 849| 102 | 48|The Dark Tower Vii: The Dark Tower| 845| 103 | 104 | */ 105 | 106 | -- 3. List the amount of time (in years) that have passed since the first published book and the last published book. 107 | 108 | SELECT 109 | MIN(year_published) AS first_published, 110 | MAX(year_published) AS last_published, 111 | (MAX(year_published) - MIN(year_published)) AS years_passed 112 | FROM 113 | stephen_king.books; 114 | 115 | /* 116 | 117 | first_published|last_published|years_passed| 118 | ---------------+--------------+------------+ 119 | 1974| 2022| 48| 120 | 121 | */ 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | -------------------------------------------------------------------------------- /source_data/sql_scripts/sql_portfolio_tutorial_no_extension: -------------------------------------------------------------------------------- 1 | /* 2 | SQL Portfolio Tutorial 3 | Author: Jaime M. Shaker 4 | Email: jaime.m.shaker@gmail.com or jaime@shaker.dev 5 | Website: https://www.shaker.dev 6 | LinkedIn: https://www.linkedin.com/in/jaime-shaker/ 7 | 8 | File Name: sql_portfolio_tutorial.sql 9 | 10 | This SQL file was created for the SQL Portfolio Tutorial as I try to show others how 11 | they can display their SQL portfolios on GitHub. 12 | 13 | */ 14 | 15 | /*********************************************** 16 | 17 | Create schema 18 | 19 | ***********************************************/ 20 | 21 | CREATE SCHEMA IF NOT EXISTS stephen_king; 22 | 23 | /*********************************************** 24 | 25 | Create Table 26 | 27 | ***********************************************/ 28 | 29 | DROP TABLE IF EXISTS stephen_king.books; 30 | CREATE TABLE stephen_king.books ( 31 | book_id INT, 32 | book_title TEXT, 33 | year_published INT, 34 | book_type TEXT, 35 | author TEXT, 36 | no_of_pages INT, 37 | goodreads_number_of_ratings INT, 38 | goodreads_avg_rating NUMERIC, 39 | PRIMARY KEY (book_id) 40 | ); 41 | 42 | /*********************************************** 43 | 44 | Copy data from CSV 45 | 46 | ***********************************************/ 47 | 48 | COPY stephen_king.books ( 49 | book_id, 50 | book_title, 51 | year_published, 52 | book_type, 53 | author, 54 | no_of_pages, 55 | goodreads_number_of_ratings, 56 | goodreads_avg_rating 57 | ) 58 | FROM '/var/lib/postgresql/source_data/csv/stephen_king_books.csv' 59 | WITH DELIMITER ',' HEADER CSV; 60 | 61 | /*********************************************** 62 | 63 | Simple Queries 64 | 65 | ***********************************************/ 66 | 67 | -- 1. How many records are in our table? 68 | 69 | SELECT 70 | COUNT(*) AS book_count 71 | FROM 72 | stephen_king.books; 73 | 74 | /* 75 | 76 | book_count| 77 | ----------+ 78 | 75| 79 | 80 | */ 81 | 82 | -- 2. List the book id, capitalized title and number of pages from the top 5 books with greatest number of pages. 83 | 84 | SELECT 85 | book_id, 86 | INITCAP(book_title) AS book_title, 87 | no_of_pages 88 | FROM 89 | stephen_king.books 90 | ORDER BY 91 | no_of_pages DESC 92 | LIMIT 5; 93 | 94 | /* 95 | 96 | book_id|book_title |no_of_pages| 97 | -------+----------------------------------+-----------+ 98 | 21|It | 1138| 99 | 55|Under The Dome | 1074| 100 | 27|Four Past Midnight | 930| 101 | 57|11/22/1963 | 849| 102 | 48|The Dark Tower Vii: The Dark Tower| 845| 103 | 104 | */ 105 | 106 | -- 3. List the amount of time that has passed since the first year published and the last. 107 | 108 | SELECT 109 | MIN(year_published) AS first_published, 110 | MAX(year_published) AS last_published, 111 | (MAX(year_published) - MIN(year_published)) AS years_passed 112 | FROM 113 | stephen_king.books; 114 | 115 | /* 116 | 117 | first_published|last_published|years_passed| 118 | ---------------+--------------+------------+ 119 | 1974| 2022| 48| 120 | 121 | */ 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | --------------------------------------------------------------------------------