Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan

SQL Query Output

EasySQL & Data Manipulation00:00
Practice interviewer
In session
5 left
00:00

Your question is SQL Query Output. Take a moment with it on the right.

Talk me through your thinking if you like. When you're confident, submit your answer and I'll grade it like a real screen (7/10 or better passes).

You need to log in / sign up to chat or submit.

Problem

Argo Data processes check and payment items for banks. Here is a small slice of its account and transaction tables, already loaded with sample rows.

CREATE TABLE accounts (
    account_id     INT PRIMARY KEY,
    customer_name  TEXT,
    balance        NUMERIC
);

INSERT INTO accounts (account_id, customer_name, balance) VALUES
    (1, 'Alice', 500),
    (2, 'Bob', 1200),
    (3, 'Chris', 0);

CREATE TABLE transactions (
    txn_id      INT PRIMARY KEY,
    account_id  INT REFERENCES accounts(account_id),
    txn_type    TEXT,
    amount      NUMERIC
);

INSERT INTO transactions (txn_id, account_id, txn_type, amount) VALUES
    (101, 1, 'deposit', 150),
    (102, 1, 'withdrawal', -50),
    (103, 2, 'deposit', 300),
    (104, 3, 'deposit', NULL);

Now consider this query:

SELECT
    a.customer_name,
    COUNT(t.txn_id) AS txn_count,
    SUM(t.amount) AS total_amount
FROM accounts a
LEFT JOIN transactions t ON a.account_id = t.account_id
GROUP BY a.customer_name
ORDER BY total_amount DESC NULLS LAST;

Write out exactly what this query returns: every row, every column value, and the order the rows come back in. Pay close attention to what NULL does inside SUM.