{"id":15187403,"url":"https://github.com/fortunewalla/birdstrikes","last_synced_at":"2025-10-02T01:31:33.907Z","repository":{"id":185253652,"uuid":"673197343","full_name":"fortunewalla/birdstrikes","owner":"fortunewalla","description":"birdstrikes database created for postgresql with simple sample queries","archived":false,"fork":true,"pushed_at":"2023-08-01T07:29:03.000Z","size":2319,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2024-09-27T18:21:25.107Z","etag":null,"topics":["birdstrikes","csv","data-analysis","data-science","database","dataset","pgsql","postgresql","practice","sample","sql","sql-query","workshop"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"zoltanctoth/smalldata-training","license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fortunewalla.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-08-01T05:08:07.000Z","updated_at":"2023-08-01T07:38:58.000Z","dependencies_parsed_at":"2023-08-01T08:51:57.073Z","dependency_job_id":null,"html_url":"https://github.com/fortunewalla/birdstrikes","commit_stats":null,"previous_names":["fortunewalla/birdstrikes"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fortunewalla%2Fbirdstrikes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fortunewalla%2Fbirdstrikes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fortunewalla%2Fbirdstrikes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fortunewalla%2Fbirdstrikes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fortunewalla","download_url":"https://codeload.github.com/fortunewalla/birdstrikes/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234922822,"owners_count":18907828,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["birdstrikes","csv","data-analysis","data-science","database","dataset","pgsql","postgresql","practice","sample","sql","sql-query","workshop"],"created_at":"2024-09-27T18:21:15.395Z","updated_at":"2025-10-02T01:31:28.282Z","avatar_url":"https://github.com/fortunewalla.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# smalldata-training\n\n## Selecting data\n\nSelect all data\n\n`SELECT * FROM birdstrikes;`\n\nSelect all \u0026 limit\n\n`SELECT * FROM birdstrikes LIMIT 10;`\n\nSelect certain fields\n\n`SELECT bird_size, cost FROM birdstrikes LIMIT 10;`\n\n## Ordering data\n\nOrder by a field\n\n`SELECT state, cost FROM birdstrikes ORDER BY cost LIMIT 10;`\n\nOrder by a multiple fields\n\n`SELECT state, cost FROM birdstrikes ORDER BY state, cost LIMIT 10;`\n\nOrder by a multiple fields\n\n`SELECT state, cost FROM birdstrikes ORDER BY state, cost LIMIT 10;`\n\nReverse ordering\n\n`SELECT state, cost FROM birdstrikes ORDER BY cost DESC;`\n\nReverse ordering by multple fields\n\n`SELECT state, cost FROM birdstrikes ORDER BY state DESC, cost;`\n\n## Renaming fields\n`SELECT bird_size as size, state FROM birdstrikes;`\n\n```\nSELECT\n    state || ' - ' || flight_date as title,\n    cost\nFROM birdstrikes\nORDER BY cost DESC;\n```\n\n## Filtering data\nFilter by field value\n\n`SELECT * FROM birdstrikes WHERE state = 'Alabama';`\n\nFilter by multiple conditions\n\n`SELECT * FROM birdstrikes WHERE state = 'Alabama' AND bird_size = 'Small';`\n\n`SELECT * FROM birdstrikes WHERE state = 'Alabama' OR state = 'Missouri';`\n\n`SELECT * FROM birdstrikes WHERE state IN ('Alabama', 'Missouri');`\n\nString operations:\n\n`SELECT state FROM birdstrikes WHERE state LIKE 'A%' OR state LIKE '%a';`\n\n`SELECT state FROM birdstrikes WHERE LOWER(state) = 'alabama';`\n\nLowercase: `LOWER`\nUppercase: `UPPER`\n\n```\nSELECT EXTRACT(DOW FROM flight_date) as day_of_week, * FROM birdstrikes;\n```\n\nIt can go complicated:\n\n```\nSELECT state, cost, bird_size FROM birdstrikes\nWHERE (LOWER(state) = 'alabama'\n        OR LOWER(state) = 'missoury')\n      AND (bird_size = 'Small')\nORDER BY cost DESC;\n```\n\n## Removing duplicates\n`SELECT DISTINCT state, size FROM birdstrikes;`\n\n## WORKSHOP\n* Hány dollár volt a legtöbb kár?\n* ^Ez melyik államban történt és milyen madár okozta?\n* Melyik az első három állam ABC sorrendben?\n* Milyen méretű madarak vannak az adatbázisban?\n* Mekkora méretű madár okozta a legnagyobb kárt Missouri-ban?\n* Hány államban történt baleset?\n* A hét melyik napján történt a legnagyobb kár?\n\n* How many dollars was the most damage?\n* ^In what state did this happen and what kind of bird caused it?\n* Which are the first three states in ABC order?\n* What size birds are in the database?\n* What size bird caused the most damage in Missouri?\n* In how many states did the accident occur?\n* On which day of the week did the greatest damage occur?\n\n* What's the maximum overall cost\n* ^^ In which state did this accident happen?\n* Display the first three states in alphabetical order?\n* Display the bird sizes (don't display the \"empty\" cell)\n* What is the size of the bird that caused the biggest damage in Missouri?\n\n## SOME more DML\n\nUpdating\n```\nUPDATE birdstrikes SET aircraft='Unknown' WHERE aircraft IS NULL;\n```\n\nDeleting\n```\nDELETE FROM birdstrikes WHERE aircraft = 'Unknown';\n```\n\nTruncating\n```\nTRUNCATE birdstrikes;\n```\n\n## Groupping and aggregation\n\nCOUNT(*)\n```\nSELECT COUNT(*) FROM birdstrikes;\n```\n\nSimple aggregations\n```\nSELECT MAX(cost) FROM birdstrikes;\n```\n\n```\nSELECT state, MAX(cost) AS max_cost FROM birdstrikes GROUP BY state ORDER BY state;\n```\n\nMultiple aggregate functions:\n```\nSELECT state, aircraft, COUNT(*), MAX(cost), MIN(cost), AVG(cost) FROM birdstrikes WHERE state LIKE 'A%' GROUP BY state, aircraft ORDER BY state, aircraft;\n```\n\n**Sometimes it doesn't work**:\n```\nSELECT aircraft, state, MAX(cost) AS max_cost FROM birdstrikes GROUP BY state ORDER BY state;\n```\n\nLet's fix it:\n```\nSELECT state, aircraft, MAX(cost) AS max_cost FROM birdstrikes GROUP BY state, aircraft ORDER BY state, aircraft;\n```\n\nYou can filter here, too:\n```\nSELECT state, aircraft, MAX(cost) AS max_cost FROM birdstrikes WHERE state LIKE 'A%' GROUP BY state, aircraft ORDER BY state, aircraft;\n```\n\nAdvanced groupping - HAVING\n```\nSELECT state, COUNT(*) FROM birdstrikes GROUP BY state HAVING COUNT(*) \u003e 100;\n```\n\n```\nSELECT state, COUNT(*) FROM birdstrikes\nWHERE state IS NOT NULL\nGROUP BY state HAVING COUNT(*) \u003e 100;\n```\n\n## WORKSHOP\n * Mégegyszer: Hány államban történt baleset? (Most egy szám legyen a képernyőn az eredmény)\n * Melyik államban történt a legtöbb összkár\n * Átlagosan melyik méretű madár mekkora kárt okoz?\n * Írasd ki madár és állam-méretenként (tehát 2 mezőn együttesen csoportosítva) a legnagyobb kár értékét.\n * ^^ Ebből irasd ki az átlagos kárt azokban az állam/méret csoportokban, ahol több, mint 1000 baleset történt\n\n* Again: In how many states did the accident occur? (Now the result should be a number on the screen)\n* In which state did the most total damage occur?\n* On average, what size bird does how much damage?\n* Write out the value of the largest damage per bird and state size (ie grouped together in 2 fields).\n* ^^ From this, write down the average damage in the states/size groups where more than 1000 accidents occurred\n\n * Which is the state with the most accidents?\n * List the average (AVG) damage caused by each bird size?\n * List the maximum (MAX) damage caused by each bird size in each state.\n * ^^ Only show those rows from the above solutions which have a bigger damage than $100000\n\n## JOINING\n```\nSELECT * FROM emberek\nJOIN varosok ON (emberek.varos_id = varosok.id);\n```\n\n```\nSELECT * FROM emberek\nINNER JOIN varosok ON (emberek.varos_id = varosok.id);\n```\n\n```\nSELECT * FROM emberek\nLEFT JOIN varosok ON (emberek.varos_id = varosok.id);\n```\n\n```\nSELECT * FROM emberek\nRIGHT JOIN varosok ON (emberek.varos_id = varosok.id);\n```\n\n```\nSELECT * FROM emberek\nFULL OUTER JOIN varosok ON (emberek.varos_id = varosok.id);\n```\n\n## Create table as SELECT\n```\nCREATE TABLE birdstrikes_denorm AS\n    SELECT b.*,s.id as state_id\n    FROM birdstrikes b\n       LEFT JOIN states s ON (b.state = s.state_name);\nALTER TABLE birdstrikes_denorm DROP state;\n```\n\n## WORKSHOP\n * Újra: Hány államban történtek balesetek?\n * Nézd meg, hogy hány sort látunk a különböző joinoknál a táblában (INNER, LEFT, RIGHT, FULL OUTER)\n \n* Again: In how many states were there accidents?\n* See how many rows we see for the different joins in the table (INNER, LEFT, RIGHT, FULL OUTER)\n\n### Using Zeppelin Notebook\n```\n%psql.sql SELECT EXTRACT(dow FROM flight_date) as week, COUNT(*) FROM birdstrikes GROUP BY week;\n```\n\n```\n%psql.sql %psql.sql SELECT bird_size, damage, count(*) FROM birdstrikes WHERE bird_size IS NOT NULL and damage IS NOT NULL GROUP BY bird_size, damage;\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffortunewalla%2Fbirdstrikes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffortunewalla%2Fbirdstrikes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffortunewalla%2Fbirdstrikes/lists"}