Skip to content
Advertisement

Converting PostgreSQL to MySQL

I am following a tutorial on how to find recurring transactions in a bank statement dataset. I have all the data needed, but I have issues getting the queries to work with MySQL. Any idea on how to convert this to MySQL?

The error is:

Update

I adjusted the SQL query based on feedback, and providing example data. Now I’m getting a different error message.

Query:

Returning the following error:

Query 1 ERROR: Can't group on 'transactions_count'

Sample table data:

id accounting_date description amount
1 2020-12-31 APPLE.COM/BILL -24.03
2 2021-01-05 ALIEXPRESS.COM ALIEXPRESS -33
3 2021-01-11 MICROSOFT*XBOX -399.60

Advertisement

Answer

This query should run in both MySQL and Postgres:

This is, in fact, Standard SQL and should run in just about any database (assuming the functionality is supported. Note the changes:

  • No unnamed columns in the CTE. I just removed the ROW_NUMBER().
  • All table references have aliases
  • The GROUP BY and ORDER BY clauses does not use positional notation.
  • The NOT NULL comparison is redundant. The BETWEEN does not return TRUE for NULL values.
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement