在mysql版本8.0.12中无法使用LEAD

时间:2018-11-26 17:10:58

标签: python mysql window-functions lead

我尝试使用mysql版本8.0.12引导一列,并且代码返回错误。有人可以帮我吗?

这是我的sql配置

mysql Ver 8.0.12 for osx10.14 on x86_64 (Homebrew)

我有这个数据集:

    member_id   date
  0 A           2013-03-29 13:11:19
  1 B           2013-03-29 13:52:41
  2 C           2013-03-29 18:46:12
  3 D           2013-03-30 06:21:50
  4 D           2013-03-30 06:22:13
  5 D           2013-03-30 06:22:21
  6 D           2013-03-30 06:30:51
  7 E           2015-04-30 07:05:53
  8 F           2015-04-30 16:45:57
  9 G           2015-04-30 17:15:14

我想获得这个

    member_id   date.                date_led                
  0 A           2013-03-29 13:11:19. NULL
  1 B           2013-03-29 13:52:41. NULL
  2 C           2013-03-29 18:46:12. NULL
  3 D           2013-03-30 06:21:50. 2013-03-30 06:22:13
  4 D           2013-03-30 06:22:13. 2013-03-30 06:22:21
  5 D           2013-03-30 06:22:21. 2013-03-30 06:30:51
  6 D           2013-03-30 06:30:51. NULL
  7 E           2015-04-30 07:05:53. NULL
  8 F           2015-04-30 16:45:57. NULL
  9 G           2015-04-30 17:15:14  NULL

所以我在python中做了这个请求

connection = pymysql.connect(host='IP',
                         user='NAME',
                         password='PASS',
                         db='DB',
                         charset='utf8mb4',
                         cursorclass=pymysql.cursors.DictCursor
                         )
request = """ SELECT member_id, date, 
   LEAD(date,1) OVER (PARTITION BY member_id ORDER BY date) nextOrderDate
   FROM action_log
"""
pd.read_sql(request, connection)

我收到此错误消息

ERROR 1064 (42000): You have an error in your SQL syntax; check the   manual that corresponds to your MySQL server version for the right syntax to use near '(PARTITION BY member_id ORDER BY date ) nextOrderDate    FROM action_log' at line 1

我在做什么错了?

非常感谢

1 个答案:

答案 0 :(得分:0)

这是由于chart.io和Windows功能所致。

相关问题