How can I use ROW_NUMBER() function (required) to display row numbers on Mysql table display?
mysql> select * from work;
+------+-----------+
| name | work_days |
+------+-----------+
| john | 5 |
| jane | 7 |
| jane | 2 |
| john | 3 |
+------+-----------+
4 rows in set (0.01 sec)
Without using ROW_NUMBER():
mysql> SELECT name,
-> AVG(work_days) AS workday_average,
-> COUNT(*) as count
-> FROM work
-> GROUP BY name
-> HAVING workday_average > 2
-> ORDER BY workday_average ASC, count DESC;
+------+-----------------+-------+
| name | workday_average | count |
+------+-----------------+-------+
| john | 4.0000 | 2 |
| jane | 4.5000 | 2 |
+------+-----------------+-------+
2 rows in set (0.00 sec)
Errors below when trying to add a row number column using ROW_NUMBER().
mysql> SELECT name,
-> ROW_NUMBER() over(PARTITION BY name ORDER BY work_days) as row_num,
-> AVG(work_days) AS workday_average,
-> COUNT(*) as count
-> FROM work
-> GROUP BY name
-> HAVING workday_average > 2
-> ORDER BY workday_average ASC, count DESC;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '(PARTITION BY name ORDER BY work_days) as row_num,
AVG(work_days) AS workday_ave' at line 2
mysql>
OVER (PARTITION. That means that your database does not support window functions, so you cannot do what you want on this database. You can upgrade the database to a more recent version.