SQLITE, Create a temp table then select from it

just wondering how i can create a temp table and then select from it further down the script.

Example.

CREATE TEMPORARY TABLE TEMP_TABLE1 AS 
Select 
L.ID,
SUM(L.cost)/2 as Costs,
from Table1 L
JOIN Table2 C on L.ID = C.ID
Where C.name  = 'mike'
Group by L.ID



Select 
Count(L.ID)
from Table1 L
JOIN TEMP_TABLE1 TT1 on L.ID = TT1.ID;
Where L.ID not in (TT1) 
And Sum(L.Cost) > TT1.Costs

Ideally I want to have a temp table then use it later in the script to reference from.

Any help would be great!

Leave a Comment