提问人:koguma 提问时间:6/20/2021 更新时间:6/20/2021 访问量:30
SQL 比较运算符 Python) 我无法通过 python 文件对 SQL 查询执行比较运算符
SQL Comparison Operator Python) I can't execute comparison operators to SQL query through python file
问:
sql = "WITH comparing_price AS (SELECT CODE, DATE, OPEN, high, low, close, volume,"\
"LEAD(OPEN, 1) OVER (PARTITION BY CODE ORDER BY DATE) AS 'd1_open',"\
"LEAD(OPEN, 2) OVER (PARTITION BY CODE ORDER BY DATE) AS 'd2_open',"\
"LEAD(OPEN, 3) OVER (PARTITION BY CODE ORDER BY DATE) AS 'd3_open',"\
"LEAD(high, 1) OVER (PARTITION BY CODE ORDER BY DATE) AS 'd1_high',"\
"LEAD(high, 2) OVER (PARTITION BY CODE ORDER BY DATE) AS 'd2_high',"\
"LEAD(high, 3) OVER (PARTITION BY CODE ORDER BY DATE) AS 'd3_high',"\
"LEAD(high, 4) OVER (PARTITION BY CODE ORDER BY DATE) AS 'd4_high',"\
"LEAD(low, 1) OVER (PARTITION BY CODE ORDER BY DATE) AS 'd1_low',"\
"LEAD(low, 2) OVER (PARTITION BY CODE ORDER BY DATE) AS 'd2_low',"\
"LEAD(low, 3) OVER (PARTITION BY CODE ORDER BY DATE) AS 'd3_low',"\
"LEAD(close, 1) OVER (PARTITION BY CODE ORDER BY DATE) AS 'd1_close',"\
"LEAD(close, 2) OVER (PARTITION BY CODE ORDER BY DATE) AS 'd2_close',"\
"LEAD(close, 3) OVER (PARTITION BY CODE ORDER BY DATE) AS 'd3_close',"\
"LEAD(volume, 1) OVER (PARTITION BY CODE ORDER BY DATE) AS 'd1_volume',"\
"LEAD(volume, 2) OVER (PARTITION BY CODE ORDER BY DATE) AS 'd2_volume',"\
"AVG(close) OVER (PARTITION BY CODE ORDER BY DATE, DATE ROWS BETWEEN 2 preceding AND 2 following) AS 'd2_MA5',"\
"AVG(close) OVER (PARTITION BY CODE ORDER BY DATE, DATE ROWS BETWEEN 7 preceding AND 2 following) AS 'd2_MA10',"\
"AVG(close) OVER (PARTITION BY CODE ORDER BY DATE, DATE ROWS BETWEEN 17 preceding AND 2 following) AS 'd2_MA20',"\
"AVG(close) OVER (PARTITION BY CODE ORDER BY DATE, DATE ROWS BETWEEN 57 preceding AND 2 following) AS 'd2_MA60',"\
"AVG(close) OVER (PARTITION BY CODE ORDER BY DATE, DATE ROWS BETWEEN 117 preceding AND 2 following) AS 'd2_MA120',"\
"STD(close) OVER (PARTITION BY CODE ORDER BY DATE, DATE ROWS BETWEEN 17 preceding AND 2 following) AS 'd2_std'"\
"FROM daily_price)"\
"SELECT * "\
"FROM comparing_price"\
"WHERE "\
"volume > 1 AND d1_volume > 1 AND d2_volume > 1"
execute(sql)
我收到一条错误消息:
pymysql.err.ProgrammingError:
(1064, "You have an error in your SQL syntax;
check the manual that corresponds to your MariaDB server version for the right syntax to use near
'> 1 AND d1_volume > 1 AND d2_volume > 1' at line 1")
我认为问题在于通过execute()发送比较运算符,因为在HeidiSQL中直接运行此查询时,它工作正常。或者有没有其他想法为什么它可能不起作用?
答: 暂无答案
评论
comparing_priceWHERE