select * from (select *,volume - lag(volume,1,0) over (partition by InstrumentID,tradingday order by InstrumentID asc, tradingday asc , volume asc ) as tmpvol from (select * from t_m5 union all select * from t_m6 ) as t_m56 ) as tmp_t1 where tmpvol > 0 order by instrumentid asc, tradingday asc, Volume asc