mySQL : 语法错误“您的 SQL 语法有误;请查看与您的 MySQL 服务器版本对应的手册以了解正确的语法
mySQL : Syntax Error "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to
我正在尝试从两个子集执行外部左连接,对结果进行排序,然后将其注入现有的 table(追加)。
我不明白为什么它是 unacceptable SQL 查询:
INSERT INTO f_grades ( tenant_code,
effective_date,
member_id,
segment_code,
ps_grade
)
(
SELECT TT.*
FROM (
SELECT T.tenant_code as tenant_code,
COALESCE(T.effective_date, CURRENT_DATE()) as effective_date,
T.member_id as member_id,
T.segment_code as segment_code,
T.ps_grade as ps_grade
FROM (
(
SELECT tenant_code,
member_id,
segment_code
FROM f_grades
WHERE effective_date = ( select MAX(DATE(effective_date)) from f_grades )
) as A
LEFT OUTER JOIN
(
SELECT partner_member_id,
effective_date,
ps_grade
FROM touchpoint.PT_Flags
) as B on A.member_id = B.partner_member_id
) as T
) as TT
);
输出错误:
[2021-12-09 22:38:42] [42000][1064] (conn=1151) 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 'T
[2021-12-09 22:38:42] [42000][1064] 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 'T
[2021-12-09 22:38:42] ) as TT
[2021-12-09 22:38:42] )' at line 15
can please someone advise?
我认为您不需要那些子查询。您可以直接连接两个表。
INSERT INTO f_grades (tenant_code, effective_date, member_id, segment_code, ps_grade)
SELECT A.tenant_code as tenant_code,
COALESCE(B.effective_date, CURRENT_DATE()) as effective_date,
T.member_id as member_id,
T.segment_code as segment_code,
B.ps_grade as ps_grade
FROM f_grades A
LEFT OUTER JOIN touchpoint.PT_Flags B
ON A.member_id = B.partner_member_id
WHERE effective_date = (select MAX(DATE(effective_date)) from f_grades)
我正在尝试从两个子集执行外部左连接,对结果进行排序,然后将其注入现有的 table(追加)。 我不明白为什么它是 unacceptable SQL 查询:
INSERT INTO f_grades ( tenant_code,
effective_date,
member_id,
segment_code,
ps_grade
)
(
SELECT TT.*
FROM (
SELECT T.tenant_code as tenant_code,
COALESCE(T.effective_date, CURRENT_DATE()) as effective_date,
T.member_id as member_id,
T.segment_code as segment_code,
T.ps_grade as ps_grade
FROM (
(
SELECT tenant_code,
member_id,
segment_code
FROM f_grades
WHERE effective_date = ( select MAX(DATE(effective_date)) from f_grades )
) as A
LEFT OUTER JOIN
(
SELECT partner_member_id,
effective_date,
ps_grade
FROM touchpoint.PT_Flags
) as B on A.member_id = B.partner_member_id
) as T
) as TT
);
输出错误:
[2021-12-09 22:38:42] [42000][1064] (conn=1151) 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 'T
[2021-12-09 22:38:42] [42000][1064] 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 'T
[2021-12-09 22:38:42] ) as TT
[2021-12-09 22:38:42] )' at line 15
can please someone advise?
我认为您不需要那些子查询。您可以直接连接两个表。
INSERT INTO f_grades (tenant_code, effective_date, member_id, segment_code, ps_grade)
SELECT A.tenant_code as tenant_code,
COALESCE(B.effective_date, CURRENT_DATE()) as effective_date,
T.member_id as member_id,
T.segment_code as segment_code,
B.ps_grade as ps_grade
FROM f_grades A
LEFT OUTER JOIN touchpoint.PT_Flags B
ON A.member_id = B.partner_member_id
WHERE effective_date = (select MAX(DATE(effective_date)) from f_grades)