为什么我不能使用此参数? MySQL数据库

时间:2018-11-22 23:50:10

标签: mysql mysql-error-1064

我正在尝试在UNION的两个选择中使用“ id”,有什么办法吗?

git log --exclude="refs/original/*" --all --format="%aN <%ae>" | sort -u

1 个答案:

答案 0 :(得分:0)

简单的答案是:在主查询中为analysis_groups定义一个别名,并在WHERE子句中引用它,

SELECT id, name, (

    SELECT DATE_FORMAT(a.time_added, '%d/%m/%Y') AS 'last_update' FROM analysis_groups ag, analysis_group_relation agr, analysis a WHERE ag.id = ag2.id AND agr.group_id = ag.id AND a.id = agr.analysis_id AND a.type != 3
    UNION
    SELECT DATE_FORMAT(a.time_added, '%d/%m/%Y') AS 'last_update' FROM analysis_groups ag, analysis_group_relation agr, analysis a, user_analysis ua WHERE agr.group_id = ag.id AND a.id = agr.analysis_id AND a.type = 3 AND ua.analysis_id = a.id AND a.id = '5bf1d6c5242f1' ORDER BY last_update LIMIT 1
) AS last_update_date 

FROM analysis_groups ag2 WHERE id != '0' ORDER BY last_update_date DESC LIMIT 20;