lundi 25 janvier 2016

Error while creating table in Python Sqlite

I am running some query and I want to store the output of the query as new table. I am using Jupyter notebook where I have connected to a sqlite database which has the table I am using in the query.

sql2="""

create table sales_fact_unique  as
(
 with min_leads as 
 ( 
  select LeadId, min(BookingCreateDate)as FirstBookingDate
  from 
   sales_fact
    where GrossRevenue <>0
  group by
   LeadId
) 

 select a.LeadId, a.FirstBookingDate, b.ArrivalDate,
  b.DepartureDate,b.DealWonSalesPersonId,
  b.GrossRevenue,b.EngineFromFinalURL,b.CampaignFromFinalUrl
 from 
  min_leads as a
inner join 
 (select * from sales_fact where grossrevenue <>0 ) as b
 on a.leadid=b.leadid 
 and a.FirstBookingDate=b.BookingCreateDate
)
;

"""


conn.execute(sql2)
conn.commit()

Here is the error I am getting.

<ipython-input-42-bc72021206b2> in <module>()
     45 
     46 
---> 47 c.execute(sql2)
     48 conn.commit()
     49 

OperationalError: near "(": syntax error

Any idea?

Aucun commentaire:

Enregistrer un commentaire