{"id":47026247,"url":"https://github.com/ohcnetwork/data-analytics-assessment","last_synced_at":"2026-03-11T23:18:42.771Z","repository":{"id":296849689,"uuid":"994711639","full_name":"ohcnetwork/data-analytics-assessment","owner":"ohcnetwork","description":null,"archived":false,"fork":false,"pushed_at":"2025-06-02T11:50:15.000Z","size":7,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-02-26T15:28:09.779Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/ohcnetwork.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-06-02T11:15:02.000Z","updated_at":"2025-06-02T11:50:19.000Z","dependencies_parsed_at":"2025-06-03T00:07:32.920Z","dependency_job_id":null,"html_url":"https://github.com/ohcnetwork/data-analytics-assessment","commit_stats":null,"previous_names":["ohcnetwork/data-analytics-assessment"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ohcnetwork/data-analytics-assessment","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ohcnetwork%2Fdata-analytics-assessment","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ohcnetwork%2Fdata-analytics-assessment/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ohcnetwork%2Fdata-analytics-assessment/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ohcnetwork%2Fdata-analytics-assessment/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ohcnetwork","download_url":"https://codeload.github.com/ohcnetwork/data-analytics-assessment/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ohcnetwork%2Fdata-analytics-assessment/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30406531,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-11T22:36:59.286Z","status":"ssl_error","status_checked_at":"2026-03-11T22:36:57.544Z","response_time":84,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":[],"created_at":"2026-03-11T23:18:42.164Z","updated_at":"2026-03-11T23:18:42.766Z","avatar_url":"https://github.com/ohcnetwork.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Task\n\n### **SQL Assessment – Data Analytics Role**\n\nDesign a *single SQL script* that a candidate can run end-to-end:\n\n1. **Create \u0026 populate the schema (done).**\n2. **Answer a set of 5 analytical questions.**\n\n---\n\n## 1 ️⃣ Schema \u0026 seed data\n\n```sql\n----------------------------------------------------------\n--  A. Core dimension tables\n----------------------------------------------------------\nCREATE TABLE customers (\n    customer_id      SERIAL PRIMARY KEY,\n    full_name        TEXT        NOT NULL,\n    country          TEXT        NOT NULL\n);\n\nCREATE TABLE products (\n    product_id       SERIAL PRIMARY KEY,\n    product_name     TEXT        NOT NULL,\n    category         TEXT        NOT NULL,\n    unit_price_usd   NUMERIC(8,2)\n);\n\n----------------------------------------------------------\n--  B. Fact table with nested JSONB\n--     • order_meta keeps flexible fields (payments, promo, etc.)\n----------------------------------------------------------\nCREATE TABLE orders (\n    order_id         SERIAL PRIMARY KEY,\n    customer_id      INT         REFERENCES customers(customer_id),\n    order_date       DATE        NOT NULL,\n    order_meta       JSONB       NOT NULL               -- nested JSONB\n    /* example structure\n       {\n         \"payment\": { \"method\": \"card\", \"card_type\": \"VISA\" },\n         \"promo\":   { \"code\": \"NEW10\", \"discount_usd\": 5.0 },\n         \"ship\":    { \"mode\": \"air\",  \"cost_usd\": 12.5 }\n       }\n    */\n);\n\n----------------------------------------------------------\n--  C. Bridge table (many-to-many) – quantity \u0026 price may vary per order\n----------------------------------------------------------\nCREATE TABLE order_lines (\n    order_id         INT REFERENCES orders(order_id),\n    product_id       INT REFERENCES products(product_id),\n    qty              INT  NOT NULL,\n    line_price_usd   NUMERIC(10,2)  NOT NULL,\n    PRIMARY KEY (order_id, product_id)\n);\n\n----------------------------------------------------------\n--  D. Sample data (minimal but covers edge cases)\n----------------------------------------------------------\nINSERT INTO customers (full_name, country) VALUES\n  ('Alice Smith',   'USA'),\n  ('Bala Iyer',     'India'),\n  ('Chen Wei',      'Singapore');\n\nINSERT INTO products (product_name, category, unit_price_usd) VALUES\n  ('Blood Glucose Monitor',  'Medical Devices',  40.00),\n  ('N95 Mask Box (20)',      'PPE',             25.00),\n  ('Tele-consult Credit',    'Services',        15.00);\n\n-- Order 1 – has promo + shipping\nINSERT INTO orders (customer_id, order_date, order_meta) VALUES\n  (1, '2025-05-01',\n   '{\n      \"payment\": { \"method\": \"card\", \"card_type\": \"AMEX\" },\n      \"promo\":   { \"code\": \"NEW10\", \"discount_usd\": 5 },\n      \"ship\":    { \"mode\": \"ground\", \"cost_usd\": 8.5 }\n    }'::jsonb);\n\n-- Order 2 – no promo, air shipping\nINSERT INTO orders (customer_id, order_date, order_meta) VALUES\n  (2, '2025-05-02',\n   '{\n      \"payment\": { \"method\": \"upi\", \"provider\": \"GPay\" },\n      \"ship\":    { \"mode\": \"air\", \"cost_usd\": 15 }\n    }'::jsonb);\n\n-- Order lines\nINSERT INTO order_lines VALUES\n  (1, 1, 2, 80.00),  -- Alice bought 2 glucose monitors\n  (1, 3, 1, 15.00),  -- and 1 tele-consult credit\n  (2, 2, 4, 100.00); -- Bala bought 4 PPE boxes\n\n```\n\n---\n\n## 2 ️⃣ Analytical questions the candidate must answer\n\n\u003e Instructions: Write one SQL query for each question. Use aliases (AS), JOINs, WITH CTEs, and JSONB operators (-\u003e, -\u003e\u003e, #\u003e\u003e) where appropriate.\n\u003e \n\n---\n\n### Q1. Total sales with shipping \u0026 promo impact\n\nReturn, per `order_id`,\n\n- **gross_line_total** (sum of `line_price_usd`)\n- **promo_discount** (value inside `order_meta → promo → discount_usd`; treat missing as 0)\n- **shipping_cost** (value inside `order_meta → ship → cost_usd`; treat missing as 0)\n- **net_total** = gross_line_total – promo_discount + shipping_cost\n\n---\n\n### Q2. Top-selling product category (by revenue)\n\nUsing all tables, compute total revenue **after discounts** for each product **category** and return the category that generated the **highest** revenue.\n\n---\n\n### Q3. Customers with \u003e 1 card brand used\n\nExtract card brand (`order_meta → payment → card_type`) for card payments only. Return every `customer_id` who has placed ≥ 2 orders with **different** card brands (e.g., one Visa, one Amex).\n\n---\n\n### Q4. Monthly order funnel view\n\nUsing a **CTE**, build an intermediate table `monthly_orders` that:\n\n| month | orders | distinct_customers | total_gross | total_net |\n\n(Use the same net calculation as Q1.) Then `SELECT *` from that CTE for May 2025.\n\n---\n\n### Q5. Country-level basket analysis (correlated sub-query or CTE)\n\nFor each `country`, list:\n\n- **avg_items_per_order** – average `SUM(qty)` per order\n- **preferred_payment_method** – the JSONB payment method that appears most often for that country (break ties alphabetically)\n\nHint: Unnest JSONB inside a sub-query or lateral join.\n\n---\n\n### Deliverables\n\n- A single `.sql` file that:\n    1. **Creates \u0026 seeds** the schema above (copy/paste allowed).\n    2. Contains each answer query clearly labelled `- Q1 …` through `- Q5 …`.\n\nCandidates should **not** alter seed values; instead, write queries that would generalise to larger data.\n\n---\n\n### Evaluation focus\n\n| Skill | Evidence in questions |\n| --- | --- |\n| Basic selects \u0026 aliases | Q1, Q2 |\n| Multi-table joins | Q1, Q2 |\n| CTE (`WITH`) usage | Q4, Q5 |\n| JSONB navigation (nested) | Q1, Q3, Q5 |\n| Analytical reasoning (aggregations, ranking, tie-break) | Q2, Q5 |\n\n*Happy querying!*\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fohcnetwork%2Fdata-analytics-assessment","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fohcnetwork%2Fdata-analytics-assessment","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fohcnetwork%2Fdata-analytics-assessment/lists"}