MySQL: Error when running a Windowing query - mysql

I am trying to execute a WINDOW query which is given below:
SELECT
DATE(ts),
oi,
avg(oi) OVER(PARTITION BY DATE(ts) )
FROM bybit_oi_1d_BTCUSD
It gives the following error:
#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 DATE(ts) )
FROM bybit_oi_1d_BTCUSD LIMIT 0, 25' at line 4

No Window functions until MySQL 8+ or MariaDB 10.2

Related

SQL - an alias was previously found when using over() in old mysql version

A sql query didn't work in old version of mysql below 8:
SELECT count(*) OVER() AS d FROM `T`
It gives this error:
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 '() AS FULLCOUNT FROM T' at line 1
You can refer to this DBFiddle:
https://dbfiddle.uk/?rdbms=mysql_5.7&fiddle=7dd651e5b2c988a7a85c76a2c83df066
to test the query with different versions.
then tell me how can I solve that issue without upgrade mysql version
because I don't have access of that server
This way :
SELECT (select COUNT(*) as d FROM T) as d
FROM T;
DEMO

dense_rank function error and not able to proceed further

I have used below query in Fiddle application for learning purpose but its throwing error:
with result as
(
select salary, dense_rank() over (order by salary desc) as 'dense_rank'
from salary
)
select salary from result where result.denserank = 3
Error:
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 '(order by salary desc) as 'DENSE_RANK' from salary' at line 1
What to do further.? Also is Mysql and postgreSql same
Apparently you're using a MySQL version that supports CTEs but does not support Window functions. MySQL 8.0.1 is such version (8.0.1 introduces CTEs for the first time and 8.0.2 introduces window functions).
You need to use a more recent version of MySQL and (ii) change where result.denserank = 3 to where result.dense_rank = 3.

Can anyone tell me how to find sum in database row wise

I'm writing this code
SELECT (Mathematics+Tech_comm.+Prog_C) As Total FROM sem1
and its throwing error:
#1064 - 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 '+Prog_C) As Total FROM sem1 LIMIT 0, 25' at line 1
SELECT SUM(col1 + col2 + col3) as Total FROM table

does mysql support intersect and minus set operator?

I'm getting an error when I'm using intersect or minus operator in MySQL. Help me with this. What is the alternative I can use instead of these operators?
select * from student_master;
intersect
select * from teacher_student_master;
Error Code: 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 'intersect select * from teacher_student_master' at line 1 0.000 sec

SQL Convert 'mm/dd/yy' string to date format

I have table named templog and I have a date column named 'tdate' which stores a string in the 'mm/dd/yy' format. I tried to convert using the following syntax but I receive an error.
SELECT convert(datetime,tdate,110) from templog
SQL query: Documentation
SELECT convert(datetime,tdate,110) from templog LIMIT 0, 25
MySQL said: Documentation
1064 - 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 'tdate,110) from templog LIMIT 0, 25' at line 1
Any ideas on what I'm doing wrong?
For MariaDB, you want str_to_date():
SELECT str_to_date(tdate, '%m/%d/%y')
FROM templog