cswork / libraryOpen practice workspace

Coding questions · Rbcroyalbank

Explain Pandas and SQL Basics

This question evaluates understanding of pandas and SQL fundamentals—specifically pandas Series vs DataFrame distinctions, SQL WHERE vs HAVING semantics, and practical duplicate-detection in transactional data—targeting data manipulation competency for Data Engineer roles.

You are interviewing for a Data Engineer internship. Answer the following short data-manipulation questions:

  1. In pandas, what is the difference between a Series and a DataFrame? Compare their dimensionality, indexing behavior, and common use cases.

  2. In SQL, what is the difference between WHERE and HAVING? Explain when each filter is applied and whether aggregate expressions can be used.

  3. Consider a table transactions_raw with the following schema:

    • ingest_id BIGINT
    • account_id BIGINT
    • transaction_id BIGINT
    • amount DECIMAL(12,2)
    • transaction_ts TIMESTAMP

    Assume transaction_ts is stored in UTC, and there are no foreign-key relationships relevant to this task. Define a duplicate as multiple rows with the same (account_id, transaction_id, amount, transaction_ts). Write a SQL query that returns all duplicate groups with the output columns: account_id, transaction_id, amount, transaction_ts, duplicate_count.

Explain Pandas and SQL Basics

Write an SQL query that, for every user id, returns the first date they were recorded as active and the last date they were recorded as inactive.

Table activity

columntypeconstraints
idINTEGER
dateDATE
active_statusVARCHAR(20)

Sample data:

active_statusdateid
active2023-01-011
inactive2023-01-101
active2023-02-011
inactive2023-01-052
active2023-03-202

Expected output

For each user ID, show first active date and last inactive date

first_active_dateidlast_inactive_date
2023-01-0112023-01-10
2023-03-2022023-01-05

Hints

  1. Use conditional aggregation (MIN/MAX with CASE) or window functions