0

I want to calculate a specific subset of data from the 1-minute data source in table M_1. Here are my scripts:

one=select code,dates, iif(deltas(J)>0,1,0) as J_up from (select * , MACD(close, 5, 34, 5) as `DIF`DEA`MACD`J from M_1 where code="000001" order by code,dates)

all=select code,dates, iif(deltas(J)>0,1,0) as J_up from (select * , MACD(close, 5, 34, 5) as `DIF`DEA`MACD`J from M_1 order by code,dates)

Using the order by clause, I performed two kinds of queries: one retrieves all data and the other filters the data by the stock ID "000001". But the results are different:

enter image description here

I don’t understand why is that. Does anyone can help me?

YaN
  • 407
  • 1
  • 6

1 Answers1

1

The cause lies in that the select statement is executed before the order by clause. The subqueries perform calculations on the data before it is sorted by “code“ and “dates“. Since the MACD function involves sequence-dependent calculations, the order of the rows differs if the query range is different, which will affect the final results. To fix your problem, first sort the M_1 by “code” and “dates” before executing the MACD.

lulunolemon
  • 219
  • 3