Google colaboratory SQLite窗口函数未在google colab笔记本中运行

Google colaboratory SQLite窗口函数未在google colab笔记本中运行,google-colaboratory,Google Colaboratory,当我试图在google colab中运行以下代码时: #Get required Data data8 = pd.read_sql_query('''SELECT Person.Name, Person.Gender FROM M_Cast left JOIN Person USING (PID) WHERE PID NOT IN ( SELECT DISTINCT(PID) as PID FROM ( S

当我试图在google colab中运行以下代码时:

    #Get required Data
    data8 = pd.read_sql_query('''SELECT  Person.Name, Person.Gender
    FROM M_Cast left JOIN Person USING (PID)
    WHERE PID NOT IN
    (
    SELECT DISTINCT(PID) as PID
    FROM
        (
        SELECT *, LEAD(M_year, 1, 0) OVER (PARTITION BY Actor ORDER BY M_year ASC) AS N_Year
        FROM
            (
            SELECT trim(person.PID) as PID, trim(Person.Name) as Actor, substr(Movie.year,length(Movie.year)-3,4) as M_Year
            FROM Person
            LEFT JOIN M_Cast USING (PID)
            LEFT JOIN Movie USING (MID)
            )
        )
    WHERE (N_Year-M_Year)>3
    )''',con)

print('Output 8: Following is the list of actors never unemployed more than 3 years.(Included actors having single movie):\n')
data8
科拉布给了我一个错误 DatabaseError:在sql上执行失败 :靠近“(”:语法错误


虽然它在我的jupyter笔记本上运行良好,但Colab中的默认sqlite版本是3.22,但3.25+支持窗口功能。因此,您需要先升级它

!add-apt-repository -y ppa:sergey-dryabzhinsky/packages
!apt update
!apt install sqlite3
然后重新启动运行时,因为之前已经加载了sqlite

MENU > Runtime > Restart runtime
然后检查它是否为新版本

import sqlite3
print(sqlite3.sqlite_version) # 3.33.0

失败代码的行号是多少?不幸的是,这在较新的colab版本中不再有效。@simonst我已将其更新到另一个ppa,以便再次有效。