You are tasked with finding the total sales for each month of the year. You have a table 'Orders' with columns 'OrderID', 'OrderDate', and 'SalesAmount'. Which query correctly calculates the monthly sales totals?
SELECT EXTRACT(MONTH FROM OrderDate) AS Month, SUM(SalesAmount) AS TotalSales FROM Orders ORDER BY Month;
SELECT MONTH(OrderDate) AS Month, SUM(SalesAmount) AS TotalSales FROM Orders ORDER BY MONTH(OrderDate);
SELECT STRFTIME('%Y-%m', OrderDate) AS Month, SUM(SalesAmount) AS TotalSales FROM Orders GROUP BY Month;
SELECT MONTH(OrderDate) AS Month, SUM(SalesAmount) AS TotalSales FROM Orders GROUP BY Month;
In SQL, a self-join is used to:
Improve query performance by reducing the number of joins.
Join a table to itself using an alias.
Join two tables with different schemas.
Combine data from multiple tables based on a common column.
Which of the following SQL statements is used to definitively save changes made within a transaction?
PERSIST
UPDATE
COMMIT
SAVE
Which of the following ACID properties ensures that any changes made within a transaction are permanent, even in case of system failures?
Durability
Consistency
Isolation
Atomicity
You are analyzing sales data and want to display the running total of sales for each month. What SQL concept would be MOST suitable for this task?
GROUP BY clause with SUM() aggregate function
Self join with aggregate function
Window function with SUM() OVER (ORDER BY...)
Correlated subquery with SUM() function
You are tasked with finding employees who do not manage any other employees. Which type of JOIN would be most suitable for this scenario?
INNER JOIN
LEFT JOIN
RIGHT JOIN
FULL OUTER JOIN
You have a table of orders and want to calculate the running total of order amounts for each customer, ordered by order date. Which SQL feature would be most efficient for this task?
Recursive CTE
Window Function
Cross Join
Self Join
Which of these is NOT a common SQL performance tuning technique?
Filtering data on indexed columns whenever possible.
Using appropriate data types for columns.
Using wildcard characters (%) at the beginning of a search pattern.
Selecting only the required columns instead of using SELECT *.
Which ACID property ensures that changes made within a transaction are permanently written to the database if the transaction succeeds?
In SQL, what is the purpose of a transaction?
To optimize query performance.
To create a backup of the database.
To retrieve data from a database.
To define a unit of work that must be executed as a whole to maintain database consistency.