我目前正在研究更长的MySQL查询,我会逐步检查它,因为它的长度可以找到问题。现在我达到了一个我无法向自己解释的地步。
在我的查询中,我调用一个子查询,其中Select与Select(子查询)相似。我曾经"建立"子查询之前和它的工作。但是在调用它时 - 为了进一步计算 - 出现了一个错误#1064 - 据我所知 - 与子查询无关,因为打开的括号全部都是关闭的,而我常常以我的方式处理子查询之前做过。
但问题必须与名为avat的查询部分和以下Select(avat)
有关。错误是#1064,解析错误。对我来说,还是其他什么新事物?
SELECT sr.usr_id_give,
sr.usr_id_get,
IFNULL((sr.value / srgive.value),0) as asv,
IF((SELECT asv) IS NULL,0.1,1) AS sv,
(SELECT IF(EXISTS(SELECT y.usr_id2, x.usr_id2 FROM usr_connx x
LEFT JOIN usr_connx y ON y.usr_id1 = x.usr_id2 AND y.usr_id2 <> x.usr_id1
LEFT JOIN usr_connx z ON z.usr_id2 = y.usr_id2 AND z.usr_id1 = x.usr_id1
WHERE x.usr_id1 = 3 AND z.usr_id1 IS NULL GROUP BY y.usr_id2 HAVING COUNT(*) >= 2),1.5,
IF(EXISTS(SELECT y.usr_id2, x.usr_id2 FROM usr_connx x
LEFT JOIN usr_connx y ON y.usr_id1 = x.usr_id2 AND y.usr_id2 <> x.usr_id1
LEFT JOIN usr_connx z ON z.usr_id2 = y.usr_id2 AND z.usr_id1 = x.usr_id1
WHERE x.usr_id1 = 3 AND z.usr_id1 IS NULL GROUP BY y.usr_id2 HAVING COUNT(*) >= 2),0.5,0))) AS grade,
((SELECT sv) * (SELECT grade)) AS vat,
(SELECT AVG(value)
FROM (SELECT srr.value
FROM skill_ratings AS srr
WHERE srr.usr_id_get = 221
AND srr.skill_id = 1
LIMIT 5) skill_ratings) as avat,
SELECT(avat)
FROM skill_ratings AS sr
LEFT JOIN skill_ratings srgive ON srgive.usr_id_get = sr.usr_id_give
WHERE sr.usr_id_get = 1
我想要完成的是它可以正常工作,我可以调用子查询,因为它在我尝试调用之前就已经工作了。
提前感谢您的帮助。也许,如果这是一个困难的问题,欢迎提供解释,以便我可以学习并避免将来出现类似的错误。
这是错误:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'SELECT(avat)
FROM skill_ratings AS sr
LEFT JOIN skill_ratings srgive ON srgi' at line 23