0

I wrote this block of code

SELECT max(order)
FROM orders_table
GROUP BY UNIX_TIMESTAMP(timestamp) DIV 30 ;

Order is a column that I'm trying to take the max of every 30 seconds from a table called orders_table. I found the last line of code on here in the answer to someone elses program. However, I get an error when I try to run this code.

Thanks in advance

GMB
  • 216,147
  • 25
  • 84
  • 135
user9069732
  • 1
  • 1
  • 4

1 Answers1

0

Your query uses MySQL syntax. In Oracle server, neither DIV nor UNIX_TIMESTAMP exists.

To do integer division, you may just TRUNC the results of the division.

To compute the number of seconds since January 1st, 1970, you could use the following expression (since Oracle, when substracting dates, returns the result as a number of days) :

(date_column - TO_DATE('1970-01-01', 'yyyy-mm-dd')) * 60 *60 *24

You probably want :

SELECT MAX(o.order)
FROM orders_table o
GROUP BY TRUNC(o.timestamp - TO_DATE('1970-01-01', 'yyyy-mm-dd')) / 30 )
GMB
  • 216,147
  • 25
  • 84
  • 135