SQL queries

Sample SQL Queries to help you get insights from your SQL data

Explore a collection of carefully curated SQL queries designed to help you extract valuable insights from your data. Whether you're analyzing sales trends, tracking customer behavior, or optimizing business processes, these queries provide practical solutions to common data challenges, empowering you to make informed decisions with ease.

  1. 01

    Find the Top 5 Highest Earning Employees by Department

    This query retrieves the top 5 highest earning employees in each department along with their department names and salaries.

    View query
  2. 02

    Calculate Year-Over-Year Revenue Growth

    This query calculates the year-over-year revenue growth for each year.

    View query
  3. 03

    Identify Customers with Consecutive Purchases Over Months

    This query identifies customers who have made purchases in three consecutive months.

    View query
  4. 04

    List All Products Never Purchased

    This query lists all products that have never been purchased.

    View query
  5. 05

    Find Employees with Salary Greater Than the Department Average

    This query finds employees whose salaries are greater than the average salary of their respective departments.

    View query
  6. 06

    Retrieve Customer Orders Along with Their Total Spend

    This query retrieves each customer's order along with the total amount they have spent across all orders.

    View query
  7. 07

    Detect Database Anomalies in Transaction Amounts

    This query detects anomalies in transaction amounts by flagging any transaction more than two standard deviations from the average.

    View query
  8. 08

    Get Monthly Active Users (MAU)

    This query calculates the number of distinct active users for each month.

    View query
  9. 09

    Calculate the Retention Rate of Users

    This query calculates user retention: the percentage of users who keep using the service in the months after their first activity.

    View query
  10. 10

    Generate a Cohort Analysis Report

    This query generates a cohort analysis report, showing how different groups of users (cohorts) retained over time.

    View query
  11. 11

    Find the Average Order Value by Customer Segment

    This query calculates the average order value for different customer segments.

    View query
  12. 12

    Identify Products with Increasing Sales Trend

    This query identifies products that have shown an increasing sales trend over the last three months.

    View query
  13. 13

    Calculate the Average Time Between Purchases

    This query calculates the average time between consecutive purchases for each customer.

    View query
  14. 14

    Identify Employees Eligible for Promotion Based on Performance

    This query identifies employees eligible for promotion based on their performance ratings over the past year.

    View query
  15. 15

    Calculate the Total Revenue from Repeat Customers

    This query calculates the total revenue generated from customers who have made more than one purchase.

    View query
  16. 16

    Find the Top 10 Most Profitable Products

    This query retrieves the top 10 most profitable products based on the total profit generated.

    View query
  17. 17

    Calculate the Churn Rate of Subscription Customers

    This query calculates the churn rate of customers who have canceled their subscriptions within the last year.

    View query
  18. 18

    Identify the Top 5 Locations with the Highest Sales

    This query identifies the top 5 locations with the highest sales revenue.

    View query
  19. 19

    Calculate the Average Customer Lifetime Value (CLV)

    This query calculates the average customer lifetime value based on historical purchase data.

    View query
  20. 20

    Find Products with the Highest Return Rate

    This query identifies products with the highest return rates.

    View query
  21. 21

    Identify Seasonal Sales Trends

    This query identifies seasonal sales trends by comparing sales across different months.

    View query
  22. 22

    Calculate the Average Resolution Time for Support Tickets

    This query calculates the average time taken to resolve support tickets.

    View query
  23. 23

    Find the Top 5 Longest-Serving Employees

    This query retrieves the top 5 longest-serving employees based on their tenure.

    View query
  24. 24

    Identify Customers with High Potential for Upselling

    This query identifies customers with high potential for upselling based on their purchase history.

    View query
  25. 25

    Calculate the Average Inventory Turnover Ratio

    This query calculates the average inventory turnover ratio to measure inventory management efficiency.

    View query
  26. 26

    Identify the Most Common Customer Complaints

    This query identifies the most common customer complaints by counting the occurrences of each complaint type.

    View query
  27. 27

    Calculate the Employee Retention Rate

    This query calculates the retention rate of employees over the past year.

    View query
  28. 28

    Identify the Top 10 Customers by Lifetime Value

    This query retrieves the top 10 customers based on their lifetime value.

    View query
  29. 29

    Calculate the Contribution Margin by Product Category

    This query calculates the contribution margin for each product category.

    View query
  30. 30

    Find the Top 5 Departments with the Highest Average Salaries

    This query identifies the top 5 departments with the highest average salaries.

    View query
  31. 31

    Identify the Most Popular Products by Region

    This query identifies the most popular products in each region based on sales quantity.

    View query
  32. 32

    Calculate the Net Promoter Score (NPS)

    This query calculates the Net Promoter Score based on customer feedback.

    View query
  33. 33

    Find Employees with No Recent Performance Reviews

    This query identifies employees who have not received a performance review in the last year.

    View query
  34. 34

    Calculate the Conversion Rate of Marketing Campaigns

    This query calculates the conversion rate of different marketing campaigns.

    View query
  35. 35

    Identify the Top 5 Suppliers by Order Volume

    This query retrieves the top 5 suppliers based on the volume of orders they fulfill.

    View query
  36. 36

    Calculate the Average Customer Satisfaction Score by Product

    This query calculates the average customer satisfaction score for each product.

    View query
  37. 37

    Identify the Most Frequently Returned Products

    This query identifies products with the most frequent returns.

    View query
  38. 38

    Calculate the Average Deal Size by Salesperson

    This query calculates the average deal size for each salesperson.

    View query
  39. 39

    Identify the Top 5 Most Engaged Users

    This query identifies the top 5 most engaged users based on their activity levels.

    View query
  40. 40

    Calculate the Average Customer Response Time for Support Tickets

    This query calculates the average time taken by customers to respond to support tickets.

    View query
  41. 41

    Identify Products with the Highest Stockout Rates

    This query identifies products that frequently go out of stock.

    View query
  42. 42

    Calculate the Average Time to Hire by Job Role

    This query calculates the average time taken to hire candidates for different job roles.

    View query
  43. 43

    Find the Top 5 Most Visited Pages on a Website

    This query retrieves the top 5 most visited pages on a website based on page views.

    View query
  44. 44

    Identify Employees with the Highest Number of Overtime Hours

    This query identifies employees who have worked the highest number of overtime hours.

    View query
  45. 45

    Calculate the Average Order Fulfillment Time

    This query calculates the average time taken to fulfill orders.

    View query
  46. 46

    Identify the Most Common Reasons for Support Ticket Escalations

    This query identifies the most common reasons for escalating support tickets.

    View query
  47. 47

    Calculate the Average Customer Acquisition Cost (CAC)

    This query calculates the average customer acquisition cost.

    View query
  48. 48

    Identify the Most Profitable Customer Segments

    This query identifies the most profitable customer segments based on total revenue.

    View query
  49. 49

    Calculate the Average Number of Items Per Order

    This query calculates the average number of items per order.

    View query
  50. 50

    Calculate the daily signup count

    Retrieve the daily count of user signups from the users table.

    View query
  51. 51

    Calculate the weekly signup count

    Retrieve the weekly count of user signups from the users table.

    View query
  52. 52

    Calculate Monthly Recurring Revenue (MRR)

    This query calculates the total monthly recurring revenue from active subscriptions.

    View query
  53. 53

    Calculate Annual Recurring Revenue (ARR)

    This query calculates the annualized recurring revenue from active subscriptions.

    View query
  54. 54

    Calculate Average Revenue Per User (ARPU)

    This query calculates the average revenue generated per user on a monthly basis.

    View query
  55. 55

    Track MRR Expansion and Contraction

    This query breaks down MRR changes into expansion, contraction, and net new revenue.

    View query
  56. 56

    Calculate Trial-to-Paid Conversion Rate

    This query calculates the percentage of trial users who convert to paid subscriptions.

    View query
  57. 57

    Calculate Revenue Churn Rate

    This query calculates the percentage of recurring revenue lost due to cancellations and downgrades.

    View query
  58. 58

    Calculate Customer Acquisition Cost by Channel

    This query calculates the cost of acquiring a customer broken down by marketing channel.

    View query
  59. 59

    Calculate LTV to CAC Ratio

    This query calculates the ratio of customer lifetime value to customer acquisition cost.

    View query
  60. 60

    Calculate Net Revenue Retention (NRR)

    This query calculates net revenue retention rate including expansions and contractions.

    View query
  61. 61

    Calculate DAU/MAU Ratio (Stickiness)

    This query calculates the ratio of daily active users to monthly active users to measure product stickiness.

    View query
  62. 62

    Track Feature Adoption Rate

    This query calculates the percentage of active users who have used a specific feature.

    View query
  63. 63

    Calculate Time to First Value (TTFV)

    This query measures the average time between user signup and their first key action in the product.

    View query
  64. 64

    Calculate User Activation Rate

    This query calculates the percentage of signups who complete a defined activation milestone.

    View query
  65. 65

    Track Signup to Activation Funnel

    This query tracks the conversion funnel from signup through each onboarding step to activation.

    View query
  66. 66

    Calculate CAC Payback Period

    This query calculates how many months it takes to recover the customer acquisition cost.

    View query
  67. 67

    Calculate SaaS Quick Ratio

    This query calculates the SaaS quick ratio by comparing new and expansion MRR to churned and contraction MRR.

    View query
  68. 68

    Identify Users at Risk of Churning

    This query identifies active subscribers who have significantly reduced their product usage.

    View query
  69. 69

    Calculate User Retention by Signup Cohort

    This query calculates retention rates for each monthly signup cohort over subsequent months.

    View query
  70. 70

    Calculate Subscription Renewal Rate

    This query calculates the percentage of subscriptions that renew at the end of their billing period.

    View query
  71. 71

    Track Plan Distribution of Active Subscribers

    This query shows the distribution of active subscribers across different pricing plans.

    View query
  72. 72

    Track Plan Upgrade and Downgrade Trends

    This query tracks the number of plan upgrades and downgrades over time.

    View query
  73. 73

    Calculate Average Session Duration

    This query calculates the average time users spend per session in the product.

    View query
  74. 74

    Calculate MRR Growth Rate Month over Month

    This query calculates the percentage growth of monthly recurring revenue compared to the previous month.

    View query
  75. 75

    Track Free-to-Paid Upgrade Rate

    This query calculates the percentage of free plan users who upgrade to a paid plan.

    View query
  76. 76

    Calculate Customer Health Score

    This query calculates a composite health score for each customer based on usage, support tickets, and billing.

    View query
  77. 77

    Track Weekly Active Users (WAU)

    This query calculates the number of distinct active users for each week.

    View query
  78. 78

    Calculate Support Ticket Volume per Customer

    This query calculates the average number of support tickets per paying customer.

    View query
  79. 79

    Identify Power Users by Activity

    This query identifies the most active users based on login frequency and feature usage.

    View query
  80. 80

    Calculate Gross Margin by Month

    This query calculates gross margin by subtracting cost of goods sold from revenue.

    View query
  81. 81

    Track API Usage by Customer

    This query tracks API call volumes per customer to monitor usage and identify heavy consumers.

    View query
  82. 82

    Calculate Lead Velocity Rate (LVR)

    This query calculates the month-over-month growth rate of qualified leads.

    View query
  83. 83

    Track Signup Source Attribution

    This query breaks down signups by their acquisition source or referral channel.

    View query
  84. 84

    Calculate Monthly Burn Rate

    This query calculates the net monthly cash burn by comparing revenue to expenses.

    View query
  85. 85

    Identify Dormant Accounts with Active Subscriptions

    This query finds paying customers who have not logged in recently.

    View query
  86. 86

    Track Invitation and Viral Growth

    This query calculates the viral coefficient by tracking user invitations and resulting signups.

    View query
  87. 87

    Calculate Expansion Revenue by Account

    This query identifies accounts that have increased their spending over time.

    View query
  88. 88

    Calculate Average Time to Close a Deal

    This query measures the average number of days from lead creation to deal closure.

    View query
  89. 89

    Calculate Revenue Concentration Risk

    This query identifies what percentage of total revenue comes from the top customers.

    View query
  90. 90

    Track Onboarding Completion Rate

    This query calculates the percentage of new users who complete all onboarding steps.

    View query
  91. 91

    Calculate Average Seats per Account

    This query calculates the average number of seats or team members per paying account.

    View query
  92. 92

    Track Failed Payments and Involuntary Churn

    This query tracks payment failures that lead to involuntary churn.

    View query
  93. 93

    Calculate Customer Effort Score (CES)

    This query calculates the average customer effort score from feedback surveys.

    View query
  94. 94

    Track Product Qualified Leads (PQLs)

    This query identifies free or trial users who meet product-qualified lead criteria based on usage.

    View query
  95. 95

    Calculate Monthly Active Teams

    This query counts the number of teams or organizations with at least one active user per month.

    View query
  96. 96

    Calculate Revenue Run Rate

    This query calculates the annualized revenue run rate based on the most recent month.

    View query
  97. 97

    Track Cancellation Reasons

    This query aggregates the reasons customers give when cancelling their subscription.

    View query
  98. 98

    Calculate Daily Revenue

    This query calculates the total revenue collected each day from all payment sources.

    View query
  99. 99

    Calculate User Engagement Score

    This query calculates a composite engagement score for each user based on multiple activity signals.

    View query
  100. 100

    Track Cumulative MRR Growth

    This query shows the cumulative growth of MRR over time from the company start.

    View query
  101. 101

    Track Churned Revenue by Plan

    This query breaks down churned MRR by pricing plan to identify which plans churn most.

    View query

Start free today

Every piece of your analytics, in one place.

Connect your database and the rest falls into place. Your first dashboard is minutes away.

No credit card required

This website uses cookies to ensure you get the best experience.