MySQL错误1064内连接

时间:2017-01-29 21:32:21

标签: mysql

我写这个SQL:

INSERT INTO registered (`idc`, `idp`, `date`)
SELECT 'idc' 
FROM course,registered
    INNER JOIN course c ON c.idc=registered.idc 
WHERE course.title='aaa',
      (SELECT `idp` FROM participant,registered
      INNER JOIN participant ON participant.idp=registered.idp WHERE 
      participant.username='mmm')

我收到此错误:

  

1064 - 您的SQL语法出错;查看与MariaDB服务器版本对应的手册,以获取正确的语法   靠近'       (SELECT idp FROM参与者,在第4行注册的INNER JOIN参与者

3 个答案:

答案 0 :(得分:1)

当然 idc int(11)PRI auto_increment title varchar(200)UNI 详细文本 参加者 idp int(11)PRI auto_increment firstname varchar(50) lastname varchar(50) username varchar(100)UNI 注册 idc int(11)unsigned PRI idp int(11)unsigned PRI 约会日期

答案 1 :(得分:0)

你可能想尝试这样的事情,你用它后面的另外两个SELECT语句设置一个父SELECT ...

INSERT INTO registered (idc, idp, date) 
  SELECT 
    (SELECT 'idc' FROM course, registered INNER JOIN course c ON c.idc=registered.idc WHERE course.title='aaa'), 
    (SELECT idp FROM participant,registered INNER JOIN participant ON participant.idp=registered.idp WHERE participant.username='mmm');

此外,您可能需要设置" date"同样。如果根据该列的定义自动设置,则可以将其保留:

INSERT INTO registered (idc, idp)...

答案 2 :(得分:0)

您的插入句子需要3个值:, idc , idp )日期SELECT 'idc',但您的选择句只提供一个:INSERT INTO registered (`idc`, `idp`, `date`) SELECT course.idc, participant.idp, <HERE A DATE> FROM registered INNER JOIN course ON course.idc = registered.idc INNER JOIN participant ON participant.idp = registered.idp WHERE course.title = 'aaa' and participant.username = 'mmm';

您应该将查询重新定义为:

Traceback (most recent call last):
  File "pyspark/sql/tests.py", line 25, in <module>
    import subprocess
  File "/home/user/anaconda3/lib/python3.5/subprocess.py", line 364, in <module>
    import signal
  File "/home/user/anaconda3/lib/python3.5/signal.py", line 3, in <module>
    from functools import wraps as _wraps
  File "/home/user/anaconda3/lib/python3.5/functools.py", line 22, in <module>
    from types import MappingProxyType
  File "/home/user/Spark/spark-2.1.0-bin-hadoop2.7/python/pyspark/sql/types.py", line 22, in <module>
    import calendar
  File "/home/user/anaconda3/lib/python3.5/calendar.py", line 10, in <module>
    import locale as _locale
  File "/home/user/anaconda3/lib/python3.5/locale.py", line 108, in <module>
    @functools.wraps(_localeconv)
AttributeError: module 'functools' has no attribute 'wraps'

但是你的INSERT语句需要一个日期字段作为第三个字段,你必须提供它。