mysql - compare max value within a range with a specific date using group by -


i want mysql query check if end date's high value greater high within 1 year range end date -1 day symbol.

max group , checking correct symbol comparison. how go on this?

my table structure is:

id  symbol date        high 1   abc    2015-01-23  45 2   abc    2015-01-22  40 3   abc    2014-01-28  33 4   xyz    2015-01-23  37 5   xyz    2015-01-20  70 6   ano    2015-01-20  170 7   je     2015-01-25  560 8   je     2015-01-23  770   select `symbol`,`high` current_high history h  date='2015-01-23'  , symbol = 'abc';  select `date`,`symbol`, max(`high`) 1_yrhigh history  date between '2014-01-23'  , '2015-01-22' , symbol='abc' 

want results if current_high > 1yr_high

so above sample table's query result should

1 abc    2015-01-23  45  8 je    2015-01-23  770 

xyz not displayed 37 < max ie 70

ano not displayed no record 2015-01-23 present

in order current high each symbol use below query

select symbol,max(high) currenthigh table date=curdate() group symbol 

in order last 1 year high except current date use below query

select symbol,max(high) lastoneyrhigh table date between (curdate()-interval 1 day-interval 1 year)-(curdate() - interval 1 day)   group symbol  

Comments

Popular posts from this blog

tcpdump - How to check if server received packet (acknowledged) -