如何解决以下关于 partition by 子句的 mysql 查询。我相信我正确地使用了这些条款

How to resolve the following mysql query on partition by clause. I believe I am using the clauses correctly

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, "You have an error in your SQL syntax; it seems the error is around: 'VARCHAR) AS param1, param2 FROM ( SELECT id, ts, param' at line 3")'

PS: 从 python

查询 mysql

你必须写

  SELECT CAST(CAST("2017-08-29" AS DATE) as CHAR(12));

不支持 varchar。