Practical PQL Exercises
Database: Accounts Payable
Exercises:
Exercise 1: Calculate the total amount of unpaid invoices for each vendor.
Exercise 2: Find the average number of days invoices are overdue for each vendor.
Exercise 3: List vendors with more than 5 overdue invoices.
Exercise 4: Calculate the total payment amount made via 'Bank Transfer' in the last 30 days.
Exercise 5: Get the name of the vendor for the invoice with the highest amount.
Exercise 6: Count the number of distinct payment methods used.
Exercise 7: For each vendor, list their invoice IDs concatenated by a comma, for invoices created this year.
Exercise 8: Find the median invoice amount for invoices due next month.
Database: Order Processing
Exercises:
Exercise 1: Calculate the total sales amount for each customer region.
Exercise 2: Find the top 3 most sold products by quantity.
Exercise 3: List customers who have placed more than 10 orders.
Exercise 4: Calculate the average order processing time (OrderDate to ShippedDate, assuming ShippedDate is in Orders table and named 'ShippedDate').
Exercise 5: Get the total number of orders placed each month of the current year.
Exercise 6: Find the percentage of orders with status 'Completed'.
Exercise 7: For each product category, find the product with the highest unit price.
Exercise 8: Identify customers who have not placed an order in the last 6 months.
Database: Financial Processes
Exercises:
Exercise 1: Calculate the total transaction amount for each account type.
Exercise 2: Find accounts with a negative balance.
Exercise 3: List the top 5 largest transactions by amount this year.
Exercise 4: Calculate the variance of transaction amounts for 'Expense' accounts.
Exercise 5: Get the running total of transaction amounts for a specific AccountID (e.g., 123) ordered by date.
Exercise 6: For each department, calculate the percentage of budget utilized (assuming a 'ActualSpend' table or column).
Exercise 7: Convert all transaction amounts from USD to EUR using a specific date's exchange rate from CurrencyRates.
Exercise 8: Find the month with the highest total transaction volume (sum of absolute amounts).
Database: HR & Payroll
Exercises:
Exercise 1: Calculate the average salary for each department.
Exercise 2: List employees hired in the last year.
Exercise 3: Find the department with the highest total payroll (sum of NetAmount from Salaries).
Exercise 4: Calculate the total number of vacation days taken by each employee this year.
Exercise 5: Get the longest serving employee's name and hire date.
Exercise 6: Count the number of employees per department.
Exercise 7: Calculate the average tenure (in years) of employees in the 'Engineering' department.
Exercise 8: Find employees whose salary is above the average salary of their department.
Database: Supply Chain Management
Exercises:
Exercise 1: Calculate the average shipment delivery time (ShipDate to DeliveryDate) for each carrier.
Exercise 2: List products with less than 10 units in stock (QuantityOnHand).
Exercise 3: Find the warehouse with the highest inventory capacity.
Exercise 4: Calculate the total number of shipments with status 'Delayed'.
Exercise 5: Get the supplier name for products that were last stocked more than 90 days ago.
Exercise 6: Count the number of distinct shipment statuses.
Exercise 7: For each warehouse, list the product IDs it stores, concatenated by a comma.
Exercise 8: Find the median quantity on hand for products in 'Electronics' category (assuming Product table is joinable).
Database: Customer Relationship Management
Exercises:
Exercise 1: Calculate the number of leads generated from each lead source this month.
Exercise 2: List contacts who have not had any activity in the last 60 days.
Exercise 3: Find the company with the most contacts.
Exercise 4: Calculate the average number of activities per contact for 'Email' type activities.
Exercise 5: Get the names of employees (AssignedTo in Leads, assuming an Employees table) who have more than 10 'Open' leads.
Exercise 6: Count the number of distinct industries among companies.
Exercise 7: For each lead source, list the statuses of leads from that source, concatenated by a comma.
Exercise 8: Find the median age of leads (CreationDate to Today) that are still in 'New' status.