http://www.perlmonks.org?node_id=233556


in reply to Re: Selecting and ordering data over multiple date ranges
in thread Selecting and ordering data over multiple date ranges

Once again gmax you've made my day better. Check it out:
"SELECT state, SUM(case when identifier BETWEEN '2003-01-01' AND '2003 +-02-01' then 1 else 0 end) AS 'Jan', SUM(case when identifier BETWEEN + '2003-02-01' AND '2003-03-01' then 1 else 0 end) AS 'Feb', COUNT(*) +as TOTAL FROM contacts WHERE state != '' GROUP BY state ORDER BY 3 DE +SC"


The 'case' instead of IF works because it's on MSQl. Also, it requires the 'then 1 else 0 end'.

Works like a charm! Soooopa Thanx

peppiv