{"id":29267630,"url":"https://github.com/sarthakagg29/sql-share-trading-analysis","last_synced_at":"2025-07-04T18:11:09.207Z","repository":{"id":302688688,"uuid":"1013311323","full_name":"sarthakagg29/sql-share-trading-analysis","owner":"sarthakagg29","description":"Analysis of share trading transactions using SQL. Includes table setup, sample data, and a variety of queries to answer typical business questions about stocks and trading.","archived":false,"fork":false,"pushed_at":"2025-07-03T18:01:55.000Z","size":551,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-07-03T18:40:49.134Z","etag":null,"topics":["data-analysis","dbeaver","portfolio","postgresql","share-market","sql"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sarthakagg29.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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-07-03T17:28:18.000Z","updated_at":"2025-07-03T18:16:14.000Z","dependencies_parsed_at":"2025-07-03T18:53:27.542Z","dependency_job_id":null,"html_url":"https://github.com/sarthakagg29/sql-share-trading-analysis","commit_stats":null,"previous_names":["sarthakagg29/sql-share-trading-analysis"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/sarthakagg29/sql-share-trading-analysis","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sarthakagg29%2Fsql-share-trading-analysis","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sarthakagg29%2Fsql-share-trading-analysis/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sarthakagg29%2Fsql-share-trading-analysis/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sarthakagg29%2Fsql-share-trading-analysis/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sarthakagg29","download_url":"https://codeload.github.com/sarthakagg29/sql-share-trading-analysis/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sarthakagg29%2Fsql-share-trading-analysis/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263594623,"owners_count":23485877,"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":["data-analysis","dbeaver","portfolio","postgresql","share-market","sql"],"created_at":"2025-07-04T18:11:07.934Z","updated_at":"2025-07-04T18:11:09.194Z","avatar_url":"https://github.com/sarthakagg29.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Share Trading Analytics \r\n\r\nI built this SQL share trading project to practice and strengthen my foundational database skills.\r\nUsing a single transactions table, I worked through real business questions step by step: creating the schema, inserting sample data, making structural tweaks, and writing essential queries.\r\n\r\nThis project is designed for anyone learning SQL—whether you’re just starting or reviewing the basics. The queries and scripts here are simple, clear, and meant to be practical examples for self-study or quick reference.\r\n\r\n\r\n## 📁 Project Structure\r\n\r\n- setup_scripts/  –  Table creation, insertion, and alterations\r\n- queries/        –  All SQL queries\r\n- docs/           –  Screenshots and outputs\r\n- README.md       –  Project summary\r\n\r\n## 🗂 Table Schema\r\n\r\nThis project uses a single table called `share_transactions` with the following columns:\r\n\r\n| Column Name       | Data Type      | Description                        |\r\n|-------------------|---------------|------------------------------------|\r\n| transaction_id    | SERIAL (PK)   | Unique identifier for each trade   |\r\n| trade_date        | DATE          | Date of transaction                |\r\n| stock_symbol      | VARCHAR(10)   | Stock/company symbol               |\r\n| quantity          | INTEGER       | Number of shares traded            |\r\n| price_per_share   | NUMERIC(10,2) | Price per share at transaction     |\r\n| broker            | VARCHAR(100)  | Broker name                        |\r\n| remarks           | VARCHAR(200)  | Extra details or notes             |\r\n\r\nBelow is the schema diagram for this table:\r\n\r\n![Table Schema](docs/visual_schema_diagram.png)\r\n\r\n## 📘 What I Tried Out\r\n\r\n- Built the table and set up all columns from scratch\r\n- Added realistic (but simple) sample share trading data\r\n- Practiced changing the table structure—like adding or removing columns\r\n- Wrote easy-to-follow SELECT queries to answer common trading questions\r\n- Included screenshots so you can see exactly what results I got\r\n\r\n## 📜 SQL Queries\r\n\r\n1. Query_1.sql – Show all transactions\r\n2. Query_2.sql – Count total number of transactions\r\n3. Query_3.sql – List all unique stock symbols\r\n4. Query_4.sql – All trades where broker is Zerodha\r\n5. Query_5.sql – List all transactions, highest to lowest price per share\r\n6. Query_6.sql – Calculate total price for each transaction\r\n7. Query_7.sql – Total shares purchased for each stock symbol\r\n8. Query_8.sql – Highest price per share in all transactions\r\n9. Query_9.sql – Mark each transaction as 'High Value' if price_per_share \u003e 2000, else 'Normal'\r\n10. Query_10.sql – Show all transactions with NULL values replaced by defaults\r\n\r\n## 🛠️ How to Use\r\n\r\n1. Run scripts from `setup_scripts/` to create and prepare the table.\r\n2. Use the queries in `queries/` to analyze the data.\r\n3. Check the `docs/` folder for screenshots and reference outputs.\r\n\r\n## 🐞 Mistakes I Made (And What I Learned)\r\n\r\nDuring this project, I ran into a few classic beginner problems—and some surprises too! Here’s what tripped me up and how I figured things out:\r\n\r\n---\r\n\r\n### Decimal Shares (Quantity Column)\r\n\r\n**What happened:**  \r\nAt first, I set the quantity column as `NUMERIC(10,2)`. It sounded logical, but then I realized—wait, you can’t actually buy half a share in real life!\r\n\r\n**How I fixed it:**  \r\nChanged the column type to `INTEGER` using `ALTER TABLE`. Easy fix, and made way more sense.\r\n\r\n---\r\n\r\n### Remarks Column Was Too Short\r\n\r\n**What happened:**  \r\nI kept running into trouble when trying to write longer notes—`VARCHAR(50)` just wasn’t enough!\r\n\r\n**How I fixed it:**  \r\nIncreased it to `VARCHAR(200)`. Now I have plenty of space for remarks.\r\n\r\n---\r\n\r\n### Unique Constraint on Trade Date\r\n\r\n**What happened:**  \r\nTotal rookie mistake: I accidentally made the `trade_date` column unique. Of course, you can have more than one trade on the same day. Got an error when inserting data.\r\n\r\n**How I fixed it:**  \r\nDropped the unique constraint—now multiple trades on the same date work fine.\r\n\r\n*Screenshot of the error:*\r\n\r\n![Unique constraint error](docs/unique_constraint_trade_date_error.png)\r\n\r\n---\r\n\r\n### Transaction IDs Didn’t Start at 1\r\n\r\n**What happened:**  \r\nAfter deleting and re-adding rows, my `transaction_id` column (auto-increment) started from 8 instead of 1.\r\n\r\n**How I fixed it:**  \r\nUsed `TRUNCATE TABLE ... RESTART IDENTITY` to reset everything so IDs start from 1 again.\r\n\r\n---\r\n\r\nMessing up and then figuring out the fixes actually helped me understand how databases work in the real world. Every mistake made things a bit clearer—and honestly, that’s the best way to learn!\r\n\r\n\r\n\r\n\r\n\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsarthakagg29%2Fsql-share-trading-analysis","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsarthakagg29%2Fsql-share-trading-analysis","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsarthakagg29%2Fsql-share-trading-analysis/lists"}