gpt4 book ai didi

UNION 的 MySql CONCATENATE 结果

转载 作者:太空宇宙 更新时间:2023-11-03 11:41:20 24 4
gpt4 key购买 nike

我想从查询并集的结果中串联一个结果...我的代码是这样的:

SELECT GROUP_CONCAT(rifDoc), idUser, user, dateDoc
FROM
(
SELECT GROUP_CONCAT(CAR.rifDoc) AS rifDoc, CAR.idUser, CAR.user, CARDETT.dateDoc
FROM car AS CAR, carDett AS CARDETT
WHERE CAR.id>0 CAR.id=CARDETT.idDoc CARDETT.dateDoc<='2017-01-31'
GROUP BY idUser, dateDoc

UNION ALL

SELECT GROUP_CONCAT(BK.rifDoc) AS rifDoc, BK.idUser, BK.user, GROUP_CONCAT(BK.inUso) AS inUso, GROUP_CONCAT(BK.inCarico) AS inCarico, BKDETT.dateDoc
FROM bike AS BK, bikeDett AS BKDETT
WHERE BK.id>0 AND BK.id=BKDETT.idDoc AND BKDETT.dateDoc<='2017-01-31'
GROUP BY idUser, dateDoc
)

GROUP BY idUser, dateDoc

但是我有这样的错误:

#1248 - Every derived table must have its own alias

有人有解决方案吗?

最佳答案

您缺少内联 View 或子查询的别名,因为错误状态如下

SELECT GROUP_CONCAT(rifDoc), idUser, `user`, dateDoc
FROM
(
SELECT GROUP_CONCAT(CAR.rifDoc) AS rifDoc, CAR.idUser, CAR.user, CARDETT.dateDoc
FROM car AS CAR, carDett AS CARDETT
WHERE CAR.id>0 CAR.id=CARDETT.idDoc CARDETT.dateDoc<='2017-01-31'
GROUP BY idUser, dateDoc

UNION ALL

SELECT GROUP_CONCAT(BK.rifDoc) AS rifDoc, BK.idUser, BK.user, GROUP_CONCAT(BK.inUso) AS inUso, GROUP_CONCAT(BK.inCarico) AS inCarico, BKDETT.dateDoc
FROM bike AS BK, bikeDett AS BKDETT
WHERE BK.id>0 AND BK.id=BKDETT.idDoc AND BKDETT.dateDoc<='2017-01-31'
GROUP BY idUser, dateDoc
) XXX <--- here

关于UNION 的 MySql CONCATENATE 结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41443352/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com