两个相同表之间的语句时的情况

时间:2018-03-15 13:55:36

标签: mysql mysql-workbench

我正在尝试计算两个相同表之间的语句以生成输出,然后仅使用其结果过滤该输出的情况。我一直收到无法找到表的错误。

USE `options`;

SELECT * FROM `table` A, `tableb` B,

(SELECT * FROM `table` A, `tableb` B,

CASE 

WHEN hour(a.quote_datetime) = 9
 AND minute(a.quote_datetime) = 31 
 AND second(a.quote_datetime) = 0 
 AND (TIMESTAMPDIFF(SECOND, a.quote_datetime, a.expiration) > 0
 AND TIMESTAMPDIFF(SECOND, a.quote_datetime, a.expiration) < 7)
 AND ((ABS((SELECT b.strike FROM `tableb` WHERE 
     b.quote_datetime = (if( dayofweek(a.quote_datetime)=2, a.quote_datetime -'65:32:00' , a.quote_datetime - '17:32:00')) AND a.strike = b.strike AND a.option_type = b.option_type AND a.expiration = b.expiration) - (SELECT b.underlying_ask FROM `tableb` WHERE b.quote_datetime = (IF( dayofweek(a.quote_datetime)=2,  a.quote_datetime -'65:32:00', a.quote_datetime - '17:32:00')) AND a.strike = b.strike AND a.option_type = b.option_type AND a.expiration = b.expiration))) BETWEEN 0.25 AND 2.75)

 AND (((SELECT b.option_type FROM `tableb` WHERE b.quote_datetime = (if( dayofweek(a.quote_datetime)=2, a.quote_datetime -'65:32:00' , a.quote_datetime - '17:32:00')) AND a.strike = b.strike AND a.option_type = b.option_type AND a.expiration = b.expiration) = 'C' AND (SELECT B.strike FROM `tableb` WHERE b.quote_datetime = (if( dayofweek(a.quote_datetime)=2, a.quote_datetime -'65:32:00' , a.quote_datetime - '17:32:00')) AND a.strike = b.strike AND a.option_type = b.option_type AND a.expiration = b.expiration) > (SELECT B.underlying_ask FROM `tableb` WHERE b.quote_datetime = (if( dayofweek(a.quote_datetime)=2, a.quote_datetime -'65:32:00' , a.quote_datetime - '17:32:00')) AND a.strike = b.strike AND a.option_type = b.option_type AND a.expiration = b.expiration))

    OR (SELECT b.option_type FROM `tableb` WHERE b.quote_datetime = (if( dayofweek(a.quote_datetime)=2, a.quote_datetime -'65:32:00' , a.quote_datetime - '17:32:00')) AND a.strike = b.strike AND a.option_type = b.option_type AND a.expiration = b.expiration) = 'P' AND (SELECT B.strike FROM `tableb` WHERE b.quote_datetime = (if( dayofweek(a.quote_datetime)=2, a.quote_datetime -'65:32:00' , a.quote_datetime - '17:32:00')) AND a.strike = b.strike AND a.option_type = b.option_type AND a.expiration = b.expiration) < (SELECT B.underlying_ask FROM `tableb` WHERE b.quote_datetime = (if( dayofweek(a.quote_datetime)=2, a.quote_datetime -'65:32:00' , a.quote_datetime - '17:32:00')) AND a.strike = b.strike AND a.option_type = b.option_type AND a.expiration = b.expiration))

 THEN ((SELECT MAX(b.bid) FROM `tableb` WHERE date(b.quote_datetime) = date(a.quote_datetime) AND a.strike = b.strike AND a.option_type = b.option_type AND a.expiration = b.expiration) - (SELECT b.ask FROM `tableb` WHERE b.quote_datetime = (if( dayofweek(a.quote_datetime)=2, a.quote_datetime -'65:32:00' , a.quote_datetime - '17:32:00')) and a.strike = b.strike AND a.optiontype = b.optiontype AND a.expiration = b.expiration))/(SELECT b.ask FROM `tableb` WHERE b.quote_datetime = (if( dayofweek(a.quote_datetime)=2, a.quote_datetime -'65:32:00' , a.quote_datetime - '17:32:00')) AND b.strike = a.strike AND b.option_type = a.option_type AND a.expiration = b.expiration)

 ELSE NULL
 END) AS All_Filter
WHERE All_Filter IS NOT NULL

0 个答案:

没有答案