Skip to content

Lesson 07 MYSQL version of the new_closing_highs #5

@JonathanLayman

Description

@JonathanLayman

If anyone is using MYSQL rather than SQLite I was able to get the new_closing_highs to work and grab the correct date by using the following command: ( to do the new_closing_lows version swap MAX with MIN )

elif stock_filter == 'new_closing_highs':
    # The inner join here allows us to grab the whole row with the proper date for MAX(close)
    cursor.execute("""
            SELECT * FROM (
                SELECT symbol, name, t1.stock_id, t1.close, t1.date
                FROM stock_price t1
                JOIN stock ON stock.id = t1.stock_id
                INNER JOIN 
                (
                    SELECT stock_id, MAX(close) as max_close
                    FROM stock_price
                    GROUP BY stock_id
                ) t2
                    ON t1.stock_id = t2.stock_id AND t1.close = t2.max_close
            ) AS t
            WHERE date = %s;
        """, (date.today().isoformat(),))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions