Skip to content
Advertisement

Combine Date and Time Fields and Order By DateTime Field

I would like to combine the date and time for meta values performance_date_1 and performance_time_1 and then sort by this new DATETIME value. Here is my SQL query so far, but no luck.

Query SQL:

SELECT TIMESTAMP(performance_date_1, performance_time_1) as DateTimeTS FROM test ORDER BY DateTimeTS;

Because of how the table is structured I am having a hard time accomplishing this. I am not sure if the Table needs to be pivoted first GROUP BY post_id column.

Schema SQL

SQL Fiddle https://www.db-fiddle.com/f/rSwxZKvBQ2JiwW5H6KawoW/1

Advertisement

Answer

You’re correct. You should make a pivot table.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement