Mastering Monthly Percent Change in SQL: Easy Quiz Quiz

  1. 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?

    1. A. DATE_TRUNC('month', date_column)
    2. B. MONTHNAME(date_column)
    3. C. GROUPDATE(date_column, 'MM')
    4. D. DATETIME_TRUN('month', date_column)
    5. E. DAT_TRUNCATE('m', date_column)
  2. 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?

    1. A. LAG(revenue_column, 1) OVER (ORDER BY month_column)
    2. B. FIRST(revenue_column, 1) OVER (ORDER BY month_column)
    3. C. LEAD(revenue_column, 1) OVER (ORDER BY month_column)
    4. D. RANK(revenue_column) OVER (ORDER BY month_column)
    5. E. LOG(revenue_column, 1) OVER (ORDER BY month_column)
  3. 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?

    1. A. ((ThisMonth - LastMonth) / LastMonth) * 100
    2. B. (ThisMonth + LastMonth) / 2
    3. C. (LastMonth / ThisMonth) * 100
    4. D. (ThisMonth - LastMonth) * 100
    5. E. ((LastMonth - ThisMonth) / LastMonth) * 100
  4. Formatting Dates for Output

    When presenting the results, which function would you use in SQL to format a date as 'YYYY-MM'?

    1. A. TO_CHAR(date_column, 'YYYY-MM')
    2. B. STRDATE(date_column, 'YYYY-MM')
    3. C. CONVERT(date_column, 'YYYY-MM')
    4. D. FORMAT_DATE('YYYY-MM', date_column)
    5. E. TO_DATE(date_column, 'YYYY-MM')
  5. 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?

    1. A. ROUND(percent_change, 2)
    2. B. CEIL(percent_change, 2)
    3. C. FLOOR(percent_change, 2)
    4. D. PRECISION(percent_change, 2)
    5. E. TRUNCATE(percent_change, 2)