---- Quarterly SELECT CASE WHEN MONTH(date_column) IN (1, 2, 3) THEN 'Q1' WHEN MONTH(date_column) IN (4, 5, 6) THEN 'Q2' WHEN MONTH(date_column) IN (7, 8, 9) THEN 'Q3' WHEN MONTH(date_column) IN (10, 11, 12) THEN 'Q4' END AS quarter, CONCAT(YEAR(date_column), CASE WHEN MONTH(date_column) IN (1, 2, 3, 4, 5, 6) THEN '-H1' WHEN MONTH(date_column) IN (7, 8, 9, 10, 11, 12) THEN '-H2' END) AS half_year, COUNT(*) AS count FROM your_table GROUP BY quarter, half_year ORDER BY quarter, half_year; --- Half Yearly SELECT YEAR(date_column), CASE WHEN MONTH(date_column) IN (1, 2, 3, 4, 5, 6) THEN 'H1' WHEN MONTH(date_column) IN (7, 8, 9, 10, 11, 12) THEN 'H2' END AS half_year, COUNT(*) AS count FROM your_table GROUP BY half_year ORDER BY half_year; Replace `date_column` with the column in your table that con
Comments
Post a Comment