8 Xero SQL Interview Questions (Updated 2024)

Updated on

March 1, 2024

At Xero, SQL does the heavy lifting for analyzing product analytics data generate from their suite of accounting and bookkeeping products. Unsurprisingly this is why Xero often tests SQL problems during interviews for Data Analyst, Data Science, and BI jobs.

To help you study for the Xero SQL interview, we've collected 8 Xero SQL interview questions – able to answer them all?

8 Xero SQL Interview Questions

SQL Question 1: Identify the "Whale" Users in Xero

Xero, an online accounting software company, relies heavily on engagement as a key factor of its business model. The most valuable users for Xero are those who use the product very frequently. We'll call those users "whale" users. In this scenario, a clear indicator of frequent use is the number of transactions a user makes within a given month. For this exercise, we want to identify the top 5 users with the most number of transactions for each month in the year 2022.

Example Input:

transaction_iduser_idtransaction_dateamount
125056701/02/2022150
130023401/03/2022200
135256701/05/202275
140023401/08/2022100
145087901/10/2022300
150012302/05/2022350
155023402/06/2022250
160056702/07/2022400
165012302/10/2022300
170067902/15/2022100

The output should include the month, user_id and count of transactions with the highest transactions count first.

Answer:


This query first groups the transactions by month and user and counts the number of transactions for each every month, it then orders the output by month and transaction_count in descending order. The at the end ensures that only the top 5 users (in terms of transaction counts) for each month are included in the final output.

To solve a super-customer analysis question on DataLemur's free online SQL code editor, try this Microsoft Azure Cloud SQL Interview Question: Microsoft SQL Interview Question: Super Cloud Customer

SQL Question 2: Analyze sales rep performance over time

Since Xero is a software company providing cloud-based accounting software, a relevant data set could be information around subscription sales. Let's say every new subscription is associated with a sales rep who closed the deal.

You are asked to calculate the running total of monthly subscription sales and the monthly ranking of sales reps by the number of closed sales.

Here are two relevant tables. "subscriptions" have details of each subscription sale, including the date of sale and its associated sales rep. "sales_reps" contains the information about the sales reps.

"subscriptions" table:

subscriptions Example Input:


"sales_reps" table:

sales_reps Example Input:


Answer:


This query first groups the sales by month and sales rep, calculating the total sales for each rep for each month. It then ranks these total sales within each month so we can see who were the top performers. The final query combines these rankings with the names of the reps from the "sales_rep" table, and orders the results by month and rank.

Example Output: (Assuming the table "subscriptions" have more data)

monthreptotal_salesrank
June 2022Eve2501
June 2022Charlie2002
July 2022Alice2001
July 2022David752

Pro Tip: Window functions are a popular SQL interview topic, so practice every window function problem on DataLemur

DataLemur Window Function SQL Questions

SQL Question 3: Could you provide a list of the join types in SQL and explain what each one does?

A join in SQL combines rows from two or more tables based on a shared column or set of columns.

Four types of JOINs exist in SQL. To demonstrate each one, say you had a table of Xero orders and Xero customers.

INNER JOIN: When there is a match in the shared key or keys, rows from both tables are retrieved. In this example, an between the Orders and Customers tables would retrieve rows where the in the Orders table matches the in the Customers table.

LEFT JOIN: A retrieves all rows from the left table (in this case, the Orders table) and any matching rows from the right table (the Customers table). If there is no match in the right table, NULL values will be returned for the right table's columns.

RIGHT JOIN: A retrieves all rows from the right table (in this case, the Customers table) and any matching rows from the left table (the Orders table). If there is no match in the left table, NULL values will be returned for the left table's columns.

FULL OUTER JOIN: A retrieves all rows from both tables, regardless of whether there is a match in the shared key or keys. If there is no match, NULL values will be returned for the columns of the non-matching table.

Xero SQL Interview Questions

SQL Question 4: Filter Customers with Outstanding Invoices

Xero is a cloud-based accounting software platform for small and medium-sized businesses. Its various products manage invoicing, bank reconciliation, bookkeeping and more. Assume you have a 'customers' table that includes details like the customer's name, the date they joined, and their total outstanding balance, plus an 'invoices' table that has invoices details including the invoice number, the customer they are linked to, the date of issue, and whether or not they are paid.

Your goal is to write a query that lists all customers from the 'customers' table who have joined after January 1, 2025, and have at least one unpaid invoice in the 'invoices' table.

Example Input

customer_idnamejoin_dateoutstanding_balance
6542ABC Corp2023-06-252000
7125XYZ Ltd2025-02-185000
8193DEF Industries2025-07-131500
6310GHI LLC2026-01-043500
9051JKL Inc2025-11-292500

Example Input

invoice_idcustomer_idissue_dateis_paid
120165422023-07-01true
128271252025-02-27false
139381932025-08-01true
140463102026-01-11false
150190512025-12-03false
160171252025-11-16true

Answer


Expected Output

customer_idnamejoin_dateoutstanding_balance
7125XYZ Ltd2025-02-185000
6310GHI LLC2026-01-043500
9051JKL Inc2025-11-292500

The query joins the 'customers' and 'invoices' tables on the customer_id, then filters for customers who joined after January 1, 2025, and have unpaid invoices. The resulting table displays the ID, name, join date, and outstanding balance of the selected customers.

SQL Question 5: What do foreign key's do?

A foreign key is a field in a database table that links to the primary key of another table, establishing a connection between the two tables. For example, let's analyze Xero's Google Ads campaigns data:

:

+------------+------------+------------+------------+ | ad_id | campaign_id| keyword | click_count| +------------+------------+------------+------------+ | 1 | 201 | Xero reviews | 120 | | 2 | 202 | Xero pricing | 150 | | 3 | 101 | buy Xero | 65 | | 4 | 101 | Xero alternatives | 135 | +------------+------------+------------+------------+

is a foreign key that connects to the of the corresponding Google Ads campaign. This establishes a relationship between the ads and their campaigns, enabling easy querying to find which ads belong to a specific campaign or which campaigns a specific ad belongs to.

The table may also have multiple foreign keys that reference primary keys in other tables. For example, and foreign keys could be used to link each ad to its ad group and the Google Ads account that the campaigns belong to, respectively.

SQL Question 6: Average Monthly Sales by Product

At Xero, we cater to businesses of various industries by providing them with online accounting software. We provide various products including Accounting & Invoices, Payroll, Projects, and Expenses. We'd like to understand our monthly sales figures by different products to better track our sales performance.

Suppose we have a table with the following columns:

  • (unique sale identification)
  • (unique product identification)
  • (unique user identification)
  • (date when sale occurred)
  • (sale amount of the product)
Example Input:
sale_iduser_idsale_dateproduct_idsale_amount
1001123502/21/20229001$75
1002456702/25/20229002$120
1003231503/10/20229001$75
1004874303/15/20229002$120
1005123504/01/20229001$75

The question is to write a SQL query that provides the average monthly sales by each product.

Answer:


This query groups rows by the month of and . For each of these groups, it calculates the average sale amount using the aggregate function. We use function to extract the month from . The result is ordered by and within that, by the month.

Example Output:
mthproduct_idavg_sales
029001$75.00
029002$120.00
039001$75.00
039002$120.00
049001$75.00

SQL Question 7: Can you explain what a cross-join is and the purpose of using them?

A cross-join, also known as a cartesian join, is a JOIN that produces the cross-product of two tables. In a cross-join, each row from the first table is matched with every row from the second table, resulting in a new table with a row for each possible combination of rows from the two input tables.

Suppose you were building a Neural Network ML model, that tried to score the probability of a customer buying a Xero product. Before you started working in Python and Tensorflow, you might want to do some Exploratory Data Analysis (EDA) in SQL, and generate all pairs of customers and Xero products.

Here's a cross-join query you could use to find all the combos:


Cross-joins are great for generating all possible combinations, but they can also create really big tables if you're not careful. For example, if you had 10,000 potential customers, and Xero had 500 different product SKUs, you'd get 5 million rows as a result!!

SQL Question 8: Joining and Analyzing Customer and Purchase Data

In this question, we are given two tables. The table provides personal data about each customer, such as their , , , and . The table logs all purchases made by customers, with columns for , , , , and .

The task is to write a SQL query that joins these two tables and determines the total quantity of each product purchased by each customer using only their and .

Example Input:
customer_idfirst_namelast_nameemail
1JohnDoejohn.doe@example.com
2JaneSmithjane.smith@example.com
3BobJohnsonbob.johnson@example.com
Example Input:
purchase_idcustomer_idproduct_idquantitypurchase_date
97821251106/18/2022 12:35:00
98452372306/20/2022 16:22:00
98921251206/21/2022 10:15:00
99373483506/22/2022 14:40:00
99932372106/23/2022 15:00:00
Example Output:
first_namelast_nameproduct_idtotal_quantity
JohnDoe2513
JaneSmith3724
BobJohnson4835

Answer:

Here is the PostgreSQL query that would yield the desired result:


This query first performs an inner join between the and tables, using as the join condition. This links each purchase to the customer who made it.

Then, it groups the joined data by , , and . For each group, it calculates the total quantity of purchases made.

Finally, the results are sorted in descending order by . This means the customers who bought the most of a certain product will appear first in the results.

Since joins come up so often during SQL interviews, try this interactive Snapchat SQL Interview question using JOINS: Snapchat JOIN SQL interview question

How To Prepare for the Xero SQL Interview

Assuming that you've already got basic SQL skills, the next best tip we have to prepare for the Xero SQL interview is to solve as many practice SQL interview questions as you can! Besides solving the above Xero SQL interview questions, you should also solve the 200+ DataLemur SQL Interview Questions which come from companies like Microsoft, Google, Amazon, and tech startups. DataLemur SQL Interview Questions

Each DataLemur SQL question has hints to guide you, step-by-step solutions and crucially, there is an online SQL code editor so you can instantly run your query and have it executed.

To prep for the Xero SQL interview it is also useful to practice SQL questions from other tech companies like:

However, if your SQL skills are weak, forget about going right into solving questions – strengthen your SQL foundations with this SQL tutorial for Data Analytics.

Free SQL tutorial

This tutorial covers SQL concepts such as Union vs. UNION ALL and transforming strings with CONCAT()/LOWER()/TRIM() – both of which pop up frequently in Xero SQL interviews.

Xero Data Science Interview Tips

What Do Xero Data Science Interviews Cover?

Besides SQL interview questions, the other topics tested in the Xero Data Science Interview are:

  • Probability & Stats Questions
  • Python or R Programming Questions
  • Open-Ended Data Case Studies
  • Machine Learning Questions
  • Behavioral & Resume-Based Questions

Xero Data Scientist

How To Prepare for Xero Data Science Interviews?

To prepare for Xero Data Science interviews read the book Ace the Data Science Interview because it's got:

  • 201 interview questions sourced from tech companies like Google & Microsoft
  • a refresher on Python, SQL & ML
  • over 900+ reviews on Amazon & 4.5-star rating

Ace the Data Science Interview by Nick Singh Kevin Huo

© 2024 DataLemur, Inc

Career Resources

Free 9-Day Data Interview Crash CourseFree SQL Tutorial for Data AnalyticsSQL Interview Cheat Sheet PDFUltimate SQL Interview GuideAce the Data Job Hunt Video CourseAce the Data Science InterviewBest Books for Data Analysts