query = """
SELECT
id,
CAST(CAST(ts AS DATE) AS VARCHAR) AS param1,
param2
FROM (
SELECT
id,
ts,
param2_long_name AS param2,
RANK() OVER (
PARTITION BY
id
ORDER BY
ts
) AS rank
FROM (
SELECT
DISTINCT
id,
ts,
param2_long_name
FROM my_table
WHERE
CAST(CAST(ts AS DATE) AS VARCHAR) > '2018-07-01'
AND id IN {ids}
)
)
WHERE
rank = 1
""".format(my_table=table, ids=ids)
收到以下错误:':(1064,“您的 SQL 语法有错误;似乎错误在附近:'VARCHAR)AS param1,param2 FROM(SELECT id,ts,param' at line 3”)'
PS:从python查询mysql