我想将查询联合的结果串联起来...我的代码是这样的:

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


有人有解决方案吗?

最佳答案

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

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

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

10-14 00:27