Compute Each Google Cloud Service's Share of Daily Net Revenue
Last updated: November 29, 2026
Quick Overview
From Google Cloud billing line items, compute each service's net revenue per day and its percentage of that day's total, in a single pass over the data.
0
0
0 solved
From Google Cloud billing line items, compute each service's net revenue per day and its percentage of that day's total, in a single pass over the data.
An online assessment style SQL item for Google Cloud finance and analytics roles. The interviewer checks whether you know that a windowed SUM can sit next to a GROUP BY result, avoiding a self-join, and whether you handle credits and division safely.
What the Interviewer Expects
- Aggregate to one row per day and service first
- Use SUM() OVER (PARTITION BY day) for the denominator
- Subtract credits to get net revenue
- Guard against a zero or negative daily total
- Order output so the biggest services appear first each day
Key Topics to Cover
How to Approach This
- Clarify the schema and expected output format before writing queries.
- Use CTEs (WITH clauses) to break complex queries into readable steps.
- Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
- Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
- For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
- How would you show each service's share of the month to date instead?
- Credits can exceed cost on some days. How should the share be reported then?
- How would you flag services whose share moved more than 5 points day over day?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice SQL ProblemsSample Answer
Clarify the Data
billing_line_items(usage_date, service_name, sku, cost_usd, credits_usd, ...) with many rows per service per day (one per SKU, project and region). Net revenue is cost minus credits; I will confirm ...
Approach
Group by day and service to get net revenue. Then, in the same SELECT, a window SUM(net_revenue) OVER (PARTITION BY usage_date) gives the daily total without joining back to a second aggregate. Wind...