I'm trying to get rows from an existing table (by columns: p_id
, e_id
, ts
, data1
, data2
, data3
) to a temporary table (indexed by p_id
, e_id
, ts
), and then selecting specific rows from that temporary table as a result. Then terminate the temporary table (because that's what CREATE TEMPORARY does, right?)
I reviewed these 2 posts:
- How to combine data into a temporary table in Mysql
- Create a temporary table in a SELECT statement without a separate CREATE TABLE
and got all confused with getting the query written properly (my query doesn't run).
CREATE TEMPORARY TABLE IF NOT EXISTS
pet_temp ( INDEX(p_id, e_id, ts) )
AS (
SELECT p_id, e_id, ts, data1, data2, data3
FROM processes_history
WHERE e_id=4362 AND ts BETWEEN '2017-03-01' AND '2017-04-01'
) SELECT p_id, e_id, ts, data1, data2, data3 FROM pet_temp WHERE p_id IN (11,22,33,44,55,66,77,88,99);