Aggregating Data by Month
Which SQL function is commonly used to group date values by the beginning of each month, as in extracting the monthly revenue from purchase data?
- A. DATE_TRUNC('month', date_column)
- B. MONTHNAME(date_column)
- C. GROUPDATE(date_column, 'MM')
- D. DATETIME_TRUN('month', date_column)
- E. DAT_TRUNCATE('m', date_column)
Calculating the Previous Month's Value
To find the previous month's revenue for each month in a table, which SQL window function would you use?
- A. LAG(revenue_column, 1) OVER (ORDER BY month_column)
- B. FIRST(revenue_column, 1) OVER (ORDER BY month_column)
- C. LEAD(revenue_column, 1) OVER (ORDER BY month_column)
- D. RANK(revenue_column) OVER (ORDER BY month_column)
- E. LOG(revenue_column, 1) OVER (ORDER BY month_column)
Monthly Percent Change Formula
Given two months' revenue values, what is the correct formula to calculate the percent change from last month to this month?
- A. ((ThisMonth - LastMonth) / LastMonth) * 100
- B. (ThisMonth + LastMonth) / 2
- C. (LastMonth / ThisMonth) * 100
- D. (ThisMonth - LastMonth) * 100
- E. ((LastMonth - ThisMonth) / LastMonth) * 100
Formatting Dates for Output
When presenting the results, which function would you use in SQL to format a date as 'YYYY-MM'?
- A. TO_CHAR(date_column, 'YYYY-MM')
- B. STRDATE(date_column, 'YYYY-MM')
- C. CONVERT(date_column, 'YYYY-MM')
- D. FORMAT_DATE('YYYY-MM', date_column)
- E. TO_DATE(date_column, 'YYYY-MM')
Rounding the Percentage Change
If you need to round the percentage change to two decimal places in SQL, which function is most appropriate to use?
- A. ROUND(percent_change, 2)
- B. CEIL(percent_change, 2)
- C. FLOOR(percent_change, 2)
- D. PRECISION(percent_change, 2)
- E. TRUNCATE(percent_change, 2)