PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates SQL data manipulation competency, focusing on aggregation filtering with HAVING and the use of window functions for running counts and ranking within a fraud analytics scenario; Category: Data Manipulation (SQL/Python).

  • easy
  • PayPal
  • Data Manipulation (SQL/Python)
  • Data Scientist

Write SQL using HAVING and window functions

Company: PayPal

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: easy

Interview Round: Technical Screen

## Context You work on fraud analytics. Assume the following schema (PostgreSQL-like types): ### `transactions` - `txn_id` BIGINT (PK) - `merchant_id` BIGINT - `user_id` BIGINT - `region` TEXT - `amount_usd` NUMERIC(12,2) - `created_at` TIMESTAMP (UTC) - `is_fraud` BOOLEAN ## Question 1 (uses `HAVING`) For the **last 30 days** (relative to `CURRENT_DATE`, assume UTC), find merchants that: - Have **at least 100 transactions**, and - Have a **fraud rate > 3%** (fraud rate = `#fraud_txns / #total_txns`). **Output columns:** `merchant_id`, `total_txns`, `fraud_txns`, `fraud_rate`. ## Question 2 (uses window functions) For each `user_id`, compute for every transaction: - The user’s **running count of transactions in the prior 7 days** ending at the transaction time (inclusive). - The user’s **rank of the transaction by recency** (1 = most recent transaction for that user). **Output columns:** `txn_id`, `user_id`, `created_at`, `txns_last_7d`, `recency_rank`.

Quick Answer: This question evaluates SQL data manipulation competency, focusing on aggregation filtering with HAVING and the use of window functions for running counts and ranking within a fraud analytics scenario; Category: Data Manipulation (SQL/Python).

Last updated: May 7, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Write SQL for top drivers and cancellation rates - PayPal (easy)
  • Write SQL to flag Venmo ATO - PayPal (Medium)
  • Write conditional aggregation SQL queries - PayPal (Medium)
  • Calculate and Find Average Contacts and Sync Percentage - PayPal (Medium)
  • Analyze Transactions and Classify by Amount in SQL - PayPal (Medium)