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 'в строке 3")'
PS: запрос mysql из python