Mysql multi-table query compares the maximum and minimum values of the two fields and displays the corresponding fields

  mysql, question

There are two tables, Table A and Table B, with the same structure but different specific fields. Under the condition of Table =, the following results were found: MAX(A.ticker_buy-B.ticker_sell) and MIN(A.ticker_buy-B.ticker_sell), i.e. the maximum and minimum values of the difference between different fields in the two tables at the same time, and the date fields corresponding to the maximum and minimum values were displayed. I tried to write them in sql statements, but the results were incorrect (compared roughly with excel). My statement reads as follows:

Select max (okcomfuturetockerquerrter.ticker _ buy-okcomfuturetockernextweek.ticker _ sell) as "maximum price difference",  Min (okcomfutureticackerquarrter.ticker _ buy-okcomfutureticackerxtweek.ticker _ sell) as "minimum price difference",  Date as "time" from okcomfuturetickerquarter  okcomfuturetickernextweek where and okcomfuturetickerquarter.ticker_buy is not null and okcomfuturetickernextweek.ticker_sell is not null ,

Please help me to write the correct query statement.


Let’s start with a long list of names …

SELECT as "time", max (a.ticker _ buy-b.ticker _ sell) as "maximum price difference", min (a.ticker _ buy-b.ticker _ sell) as "minimum price difference" FROM a,b
 AND a.ticker_buy IS NOT NULL
 AND b.ticker_sell IS NOT NULL