We are trying to get the length of a physical exercise by using the timestamps on our sensor data.
We currently have the following query:
SELECT UNIX_TIMESTAMP(
SELECT HAAS2.trainingsdata.timestamp
FROM HAAS2.trainingdata
WHERE HAAS2.trainingsdata.training_id= 1
ORDER BY timestamp DESC LIMIT 1)
- UNIX_TIMESTAMP(
SELECT HAAS2.trainingsdata.timestamp
FROM HAAS2.trainingdata
WHERE HAAS2.trainingsdata.training_id= 1
ORDER BY timestamp ASC LIMIT 1)
AS output
(enters added for readability)
When testing this query in phpMyAdmin we get 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 'SELECT HAAS2.trainingsdata.timestamp FROM HAAS2.trainingdata
WHERE HAAS2.trainin' at line 1
We've tried different ways to write down the query all resulting in the same error. We don't understand where the syntax error lies.
SELECT max(UNIX_TIMESTAMP(timestamp)) -
min(UNIX_TIMESTAMP(timestamp)) AS output
FROM HAAS2.trainingdata
WHERE training_id = 1
Related
EDIT: This solved my problem:
select id_t,punctaj
from test
where punctaj in (select punctaj from test )
order by punctaj desc
limit 1;*
I have written a working Oracle SQL code but when I'm trying to convert it to MySQL I have a syntax error which I cannot solve. It looks like MySQL does not accept ROWNUM and also SELECT * FROM a subquery. What could be the solution? I need the biggest value of "PUNCTAJ" from the tests and I need to keep that "IN". Thanks!
Here is my code:
select* from (
select id_t,punctaj
from test
where punctaj in (select punctaj from test )
order by punctaj desc)
where rownum<=1
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 'where rownum<=1 LIMIT 0, 25' at line 6
you have written twice the where condition,
In secondd where use AND rownum<=1
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
i'm trying to run this in sql query, but not working. I tried single cast, it works fine, but when i tried to add two cast, it gives 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 'FROM useradvert WHERE optionsalerent='For sale' ORDER BY cast (rm as signed)' at line 1
This query below works.
SELECT * FROM popol WHERE optsale='For sale' ORDER BY cast(rm as signed) ASC
THis one doesn't work
SELECT * FROM popol WHERE optsale='For sale' ORDER BY cast(rm as signed) ASC, cast(salary as signed) ASC
I need to output both rm and salary rm. Both are integer values. Tqs in advance.
I am trying to get a single random row from all the rows that satisfy the where clause in the SQL. I am using the following SQL but getting the corresponding error.
SELECT * FROM xyz WHERE (long='0' AND lat='0') ORDER BY RAND() LIMIT 1
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 'long='0' AND lat='0') ORDER BY RAND() LIMIT 1' at line 1
LONG is Reserved Words
SELECT * FROM xyz WHERE (`long`='0' AND lat='0') ORDER BY RAND() LIMIT 1
SELECT *
FROM ( SELECT *
FROM xyz
WHERE (`long`='0' AND lat='0')
ORDER BY DBMS_RANDOM.VALUE) LIMIT 1
I got this error when I'm trying a script.
mySQL query error: SELECT * FROM ibf_store_shopstock WHERE is_hidden='0' AND category=1 ORDER BY item_name ASC LIMIT 0,
mySQL 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 '' at line 1
mySQL error code:
Date: Monday 23rd 2012f July 2012 05:37:44 PM`
This is odd, since the very same script I tried on my localhost (MySQL 5.5.14) works just fine, but when I try it on live server (MySQL 5.1.63), it results in this error. I thought there's no big difference between the MySQL version?
Anyway here is a part of the suspected script (it's quite long):
http://pastebin.com/YaQwVPqT
I think you are missing something after LIMIT clause "LIMIT start_record", "offset"
try
SELECT *
FROM ibf_store_shopstock
WHERE is_hidden='0' AND
category=1
ORDER BY item_name ASC
LIMIT 0, 10;