{"id":29040445,"url":"https://github.com/imran-imtiaz48/sql-query-optimization-showcase","last_synced_at":"2025-10-05T18:16:37.912Z","repository":{"id":301276627,"uuid":"1008730264","full_name":"Imran-imtiaz48/SQL-Query-Optimization-Showcase","owner":"Imran-imtiaz48","description":"Real-world SQL queries with optimized versions for performance tuning and best practices.","archived":false,"fork":false,"pushed_at":"2025-06-26T03:18:25.000Z","size":55,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-06-26T03:32:13.507Z","etag":null,"topics":["optimization","performance","sql","sqlserver","testing","tuning"],"latest_commit_sha":null,"homepage":"https://www.linkedin.com/in/imranimtiaz1/","language":"TSQL","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Imran-imtiaz48.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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-06-26T02:30:14.000Z","updated_at":"2025-06-26T03:18:28.000Z","dependencies_parsed_at":"2025-06-26T03:42:24.660Z","dependency_job_id":null,"html_url":"https://github.com/Imran-imtiaz48/SQL-Query-Optimization-Showcase","commit_stats":null,"previous_names":["imran-imtiaz48/sql-query-optimization-showcase"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Imran-imtiaz48/SQL-Query-Optimization-Showcase","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Imran-imtiaz48%2FSQL-Query-Optimization-Showcase","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Imran-imtiaz48%2FSQL-Query-Optimization-Showcase/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Imran-imtiaz48%2FSQL-Query-Optimization-Showcase/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Imran-imtiaz48%2FSQL-Query-Optimization-Showcase/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Imran-imtiaz48","download_url":"https://codeload.github.com/Imran-imtiaz48/SQL-Query-Optimization-Showcase/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Imran-imtiaz48%2FSQL-Query-Optimization-Showcase/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278495420,"owners_count":25996589,"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","status":"online","status_checked_at":"2025-10-05T02:00:06.059Z","response_time":54,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["optimization","performance","sql","sqlserver","testing","tuning"],"created_at":"2025-06-26T14:05:30.507Z","updated_at":"2025-10-05T18:16:37.906Z","avatar_url":"https://github.com/Imran-imtiaz48.png","language":"TSQL","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SQL Query Optimization Showcase\n\nThe project contains a collection of complex SQL queries followed by their optimized versions. It's intended to help database professionals understand performance bottlenecks and apply optimization techniques.\n\n## 📁 Folder Structure\n- `queries/`: Original and optimized SQL query pairs.\n- `tips/sql_query_tips.md`: Best practices and tips for writing efficient SQL.\n- `README.md`: Overview and instructions.\n\n## 📋 About the Queries\n\n1. **Query 01:**  \n   Complex join to retrieve active customers’ orders along with product details.\n\n2. **Query 02:**  \n   Payroll calculation combining employee details, departments, bonuses, and salaries.\n\n3. **Query 03:**  \n   Monthly top-selling products report with aggregated sales quantities.\n\n4. **Query 04:**  \n   Customer retention analysis comparing orders made this year vs previous years.\n\n5. **Query 05:**  \n   Inventory restocking suggestions for products below reorder level.\n\n6. **Query 06:**  \n   Donation summary grouped by donor type and donation year.\n\n7. **Query 07:**  \n   Report of overdue invoices including days overdue and customer info.\n\n8. **Query 08:**  \n   Daily and weekly user login counts to monitor activity.\n\n9. **Query 09:**  \n   Aggregation of key KPIs such as total customers, recent orders, average payment, and total stock.\n   \n### 🛠️ Setup Sample Data\n\nTo test queries, first create tables and insert sample data by running:\n\n```sql\nsource sample_data.sql;\n\n## ⚡ Performance Benchmarks\n\n| Query No. | Description                                   | Original Execution Time | Optimized Execution Time | Improvement (%) |\n|-----------|-----------------------------------------------|-------------------------|--------------------------|-----------------|\n| 01        | Customer orders with product details           | 1200 ms                 | 450 ms                   | 62.5%           |\n| 02        | Payroll calculation with bonuses and salary   | 1500 ms                 | 600 ms                   | 60.0%           |\n| 03        | Monthly top-selling products                    | 1000 ms                 | 350 ms                   | 65.0%           |\n| 04        | Customer retention analysis                      | 1300 ms                 | 520 ms                   | 60.0%           |\n| 05        | Inventory restocking suggestions                 | 900 ms                  | 400 ms                   | 55.5%           |\n| 06        | Donation summary by donor and year               | 1100 ms                 | 430 ms                   | 60.9%           |\n| 07        | Overdue invoice report with days overdue         | 1250 ms                 | 480 ms                   | 61.6%           |\n| 08        | Daily and weekly user login counts                | 1000 ms                 | 370 ms                   | 63.0%           |\n| 09        | Aggregation of key KPIs                            | 1400 ms                 | 520 ms                   | 62.8%           |\n\n*Execution times are illustrative and may vary depending on data volume and environment.*\n\n## 🔧 How to Access (Using Git Bash)\n\n```bash\ngit clone https://github.com/yourusername/SQL-Query-Optimization-Showcase.git\ncd SQL-Query-Optimization-Showcase\ncat queries/01_large_query.sql\n```\n\n## ⚡ Performance Benchmarking\n\nThis project includes a SQL script `benchmark_queries.sql` to measure and record execution times of all queries.\n\n### How to use:\n\n1. Make sure your database is set up with the sample data (see `sample_data.sql`).\n2. Open and review `benchmark_queries.sql`.\n3. Replace the placeholder queries with your actual SQL queries if needed.\n4. Run the script in your SQL Server environment.\n5. View the results in the `QueryBenchmarkResults` table, which stores execution times for each query.\n\nYou can run this script for both original and optimized queries to compare performance improvements.\n\nYou can also open these files in any SQL IDE like DBeaver, SSMS, or DataGrip.\n\n## 🎯 Use Cases\n\n- Performance tuning practice  \n- SQL portfolio for job interviews  \n- Teaching and internal workshops  \n- Learning query design patterns  \n- Benchmarking and performance analysis\n\n## 📌 Tips\nSee [sql_query_tips.md](tips/sql_query_tips.md) for useful query writing guidelines.\n\n## 📬 Contributions\nFeel free to fork, optimize more queries, or add examples!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimran-imtiaz48%2Fsql-query-optimization-showcase","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fimran-imtiaz48%2Fsql-query-optimization-showcase","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimran-imtiaz48%2Fsql-query-optimization-showcase/lists"}