-1
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

4

1 回答 1

1

你必须写

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

不支持 varchar。

于 2019-06-11T22:10:05.337 回答