Hi all,
again I am stuck with counting something in MySQL. The database structure is far from SOers´d call optimal, but nevertheless I do not have an influence here and have to live with it. Probably that´s one of the reasons why I need help again to get some information out of it :)
Assume I have: some_id (not the PK of the table, not unique), year, month (no date fields just two integer fields), some_flag (character that is either A or B) .
Now I´d like to know how often some_flag has changed (in a given time span). The time span is not utterly important in the first approach, I just need to know how many changes happened. Note that changes can only happen monthly. My query:
SELECT some_id,year,some_flag FROM mytable
WHERE some_flag = "A" OR someflag = "B"
AND year > 2005
GROUP BY some_id,some_flag
HAVING COUNT(DISTINCT some_flag) > 1
returns an empty result set. What´s wrong with it? I am sure there are years in which the flag changes over months...
Isn't something like
select .... , sum(case when month=month-1 and some_flag != some_flag then 1 else 0 end) as changecount
possible ?