Problem · Database

Internet Service Provider Monthly Report

EasyPoint72 logoPoint72INTERNNEW GRADOA

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_traffic is the sum of that client's traffic amounts in May.
  • total_cost is total_traffic * tariff, rounded once to two decimal places. For example, 5.004 becomes 5.00.
  • Order rows by the returned total_cost descending, then by mac_address ascending.

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 as 00: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 5 in 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.005 becomes 5.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

MySQLPostgreSQLPandas

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

ColumnTypeNullableDescription
idPKIntegerNoUnique client identifier.
mac_addressTextNoUnique MAC address in uppercase XX:XX:XX:XX:XX:XX hexadecimal format.
tariffDecimalNoCost per traffic unit, at most three fractional digits.

traffic

ColumnTypeNullableDescription
client_idIntegerNoClient that generated this traffic event.
recorded_atTimestampNoTimezone-free calendar timestamp.
amountDecimalNoNonnegative traffic units, at most two fractional digits.

Foreign key: client_id clients(id)

Expected result

Your query or function must return these columns.

ColumnTypeNullableDescription
mac_addressTextNoClient MAC address.
total_trafficDecimalNoExact sum of all May traffic amounts.
total_costDecimalNoExact 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 <= 100 and 0 <= traffic.length <= 2000.
  • Client IDs are integers from 1 through 1000000000.
  • Traffic amounts are nonnegative decimals at most 1000000, with at most two fractional digits.
  • Tariffs are decimals from 0 through 1000, with at most three fractional digits.
  • Timestamp years range from 1990 through 2037. All timestamps are valid timezone-free calendar values.
  • The table rules in the statement apply to every case, including empty tables.

More Point72 problems