Internet Service Provider Monthly Report
Problem statement
An Internet service provider wants a billing report for client traffic recorded in May. Each client has a MAC address and a tariff per unit of traffic.
Using the clients and traffic tables, return mac_address, total_traffic, and total_cost for each client with at least one May traffic event.
total_trafficis the sum of that client's traffic amounts in May.total_costistotal_traffic * tariff, rounded once to two decimal places. For example,5.004becomes5.00.- Order rows by the returned
total_costdescending, then bymac_addressascending.
For this exercise, assume the following table and billing rules:
clients(id, mac_address, tariff)has one row per client. IDs and MAC addresses are unique. MAC addresses use six uppercase hexadecimal pairs separated by colons, such as00:00:00:00:00:0A.traffic(client_id, recorded_at, amount)has one row per traffic event. Every row references a client. There are no null values. Identical traffic rows represent separate events and all count.- May means calendar month
5in every input year. Timestamps are timezone-free calendar values; do not restrict the report to one year. - Include a client with a May event even when its total traffic or cost is zero. Omit clients with no May event.
- Compute with exact decimal values. Round cost only after summing traffic and multiplying by the tariff; halfway values round away from zero, so
5.005becomes5.01. Use rounded costs for sorting.
In MySQL and PostgreSQL, write a query over the supplied tables. In Pandas, implement monthly_report(clients, traffic) and return a DataFrame with the three result columns in the stated order.
Table schema
Use the same input data with any supported language. Open the Schema tab in the editor to see the generated SQL setup or Pandas DataFrames.
clients
| Column | Type | Nullable | Description |
|---|---|---|---|
| idPK | Integer | No | Unique client identifier. |
| mac_address | Text | No | Unique MAC address in uppercase XX:XX:XX:XX:XX:XX hexadecimal format. |
| tariff | Decimal | No | Cost per traffic unit, at most three fractional digits. |
traffic
| Column | Type | Nullable | Description |
|---|---|---|---|
| client_id | Integer | No | Client that generated this traffic event. |
| recorded_at | Timestamp | No | Timezone-free calendar timestamp. |
| amount | Decimal | No | Nonnegative traffic units, at most two fractional digits. |
Foreign key: client_id → clients(id)
Expected result
Your query or function must return these columns.
| Column | Type | Nullable | Description |
|---|---|---|---|
| mac_address | Text | No | Client MAC address. |
| total_traffic | Decimal | No | Exact sum of all May traffic amounts. |
| total_cost | Decimal | No | Exact total multiplied by tariff, rounded once to two decimal places. |
Row order: must match exactly. Numeric tolerance: 0.
Constraints
- For this exercise, assume
0 <= clients.length <= 100and0 <= traffic.length <= 2000. - Client IDs are integers from
1through1000000000. - Traffic amounts are nonnegative decimals at most
1000000, with at most two fractional digits. - Tariffs are decimals from
0through1000, with at most three fractional digits. - Timestamp years range from
1990through2037. All timestamps are valid timezone-free calendar values. - The table rules in the statement apply to every case, including empty tables.