FastPrepStatus Changes in Log Data

Status Changes in Log Data

Mastercard logoMastercard● MediumFULLTIMEPHONE SCREEN

Problem statement

Each row in status_logs records the status of one entity at an event time.

Within each entity, order logs by event_time and then log_id. Return every noninitial row whose status differs from the immediately preceding row for that entity.

Include both the previous and current status for each transition.

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.

status_logs

ColumnTypeNullableDescription
log_idPKIntegerNo—
entity_idIntegerNo—
event_timeTimestampNo—
statusTextNo—

Expected result

Your query or function must return these columns.

ColumnTypeNullableDescription
log_idIntegerNo—
entity_idIntegerNo—
event_timeTimestampNo—
previous_statusTextNo—
current_statusTextNo—

Row order: must match exactly. Numeric tolerance: 0.

Constraints

  • log_id is unique.
  • Status comparisons are exact and case-sensitive.
  • Rows with the same event_time are ordered by log_id.
  • The first row for an entity is not a status change.
  • Sort by entity_id, event_time, and log_id ascending.

More Mastercard problems

See Mastercard hiring insights