1

I am using below SQL query. This query is working fine in local but getting error in live server.

SELECT 
   id, user_id, total_usage, 
   DATE(created_at) as cre_date, 
   DATE_FORMAT(DATE(created_at), '%M %Y') as month_year, 
   ROW_NUMBER() OVER (PARTITION BY YEAR(created_date),
   MONTH(created_date) ORDER BY id DESC) as row_rank
FROM daily_usage
WHERE user_id = 1

I am getting below errors.

Static analysis:

3 errors were found during analysis.

An alias was previously found. (near "row_rank" at position 212)
An alias was expected. (near " " at position 211)
Unexpected token. (near "row_rank" at position 212)
SQL query: Documentation

SELECT id, user_id, total_usage, DATE(created_at) as cre_date, DATE_FORMAT(DATE(created_at), '%M %Y') as month_year, ROW_NUMBER() OVER (PARTITION BY YEAR(created_date), MONTH(created_date) ORDER BY id DESC) as row_rank FROM daily_usage WHERE user_id = 1

MySQL said: Documentation

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(PARTITION BY YEAR(created_date), MONTH(created_date) ORDER BY id DESC) as row_r' at line 2
Bill Karwin
  • 538,548
  • 86
  • 673
  • 828

0 Answers0