mysql - List changes of options by week -


we have database table lists option changes way:

date | option | value

01/07/08 | optiona | value_a

01/07/08 | optionb | value_b

02/07/08 | optiona | value_a2

we assume before first date has option (primary key date , option) there's no option set. have make every day, each option overrides previous changes afterwards, not backwards.

i know how can join table can get, each week, full set of values latest values per option. following:

date | option | value

01/07/08 | optiona | value_a

01/07/08 | optionb | value_b

02/07/08 | optiona | value_a2

02/07/08 | optionb | value_b

hoping got question right

create table test.stack ( date date , option_field varchar(50) , value int(5) )

truncate table test.stack; replace test.stack values ('08/07/01', 'optiona', 5) , ('08/07/01', 'optionb', 6) , ('08/07/02', 'optiona', 11) , ('08/07/02', 'optionb', 33) , ('08/07/22', 'optionb', 43) , ('08/07/24', 'optionb', 235) , ('08/07/02', 'optiona', 9) , ('08/07/22', 'optiona', 465) , ('08/07/24', 'optiona', 421) ;

select ts.date, ts.option_field, ts.value ( select s.date, s.option_field, s.value, week(s.date) week_no, max(dayofmonth(s.date)) day_no test.stack s group s.option_field, week_no ) ts ;

ps: have not checked performance


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -