All pastes #209537 Raw Edit

Mine

public sql v1 · immutable
#209537 ·published 2006-10-19 06:33 UTC
rendered paste body
-- show the expenses for each month, yields 30 recordsSELECT DATE_FORMAT(day, '%Y-%m') as month, FORMAT(SUM(amount), 2) as sumFROM tt_financesGROUP BY YEAR(day), MONTH(day)-- get the number of different months with expenses, should yield 1 record, but yields 30 records with counts between 1 and 34SELECT COUNT(1)FROM tt_financesGROUP BY YEAR(day), MONTH(day)-- now I've come up with this working querySELECT COUNT(1)FROM (  SELECT 1  FROM tt_finances  GROUP BY MONTH(day), YEAR(day)) AS FOO