我已经阅读了所有相关问题但却无法解决这个问题。我想连接这个查询的结果:
SELECT DISTINCT ord.uid AS u
FROM `uc_order_products` ord_prod, `uc_orders` ord, `uc_roles_expirations` re
WHERE ord.order_id = ord_prod.order_id
AND ord_prod.title LIKE '2012. évi%'
AND ord.uid NOT
IN (SELECT uid FROM uc_roles_expirations re)
看起来像这样:
U
----
1234
1235
...
这就是我的尝试:
SELECT GROUP_CONCAT(DISTINCT ord.uid AS u
FROM `uc_order_products` ord_prod, `uc_orders` ord, `uc_roles_expirations` re
WHERE ord.order_id = ord_prod.order_id
AND ord_prod.title LIKE '2012. évi%'
AND ord.uid NOT
IN (SELECT uid FROM uc_roles_expirations re) SEPARATOR ',')
..并没有奏效。你能帮帮我吗?
答案 0 :(得分:2)
只有columnName应该在GROUP_CONCAT
函数中。
SELECT GROUP_CONCAT(DISTINCT ord.uid SEPARATOR ',')AS u
FROM `uc_order_products` ord_prod,
`uc_orders` ord,
`uc_roles_expirations` re
WHERE ord.order_id = ord_prod.order_id
AND ord_prod.title LIKE '2012. évi%'
AND ord.uid NOT
IN (SELECT uid FROM uc_roles_expirations re)
PS:作为旁注,由于此表uc_roles_expirations
缺少连接条件,此uqery将产生笛卡尔结果。表格在另一张桌子上的关系是什么?
我不确定,但我认为你想要这个查询的结果,
SELECT GROUP_CONCAT(DISTINCT ord.uid SEPARATOR ',')AS u
FROM `uc_order_products` ord_prod
INNER JOIN `uc_orders` ord
ON ord.order_id = ord_prod.order_id
WHERE ord_prod.title LIKE '2012. évi%' AND
ord.uid NOT IN (SELECT uid FROM uc_roles_expirations)
答案 1 :(得分:1)
select GROUP_CONCAT(u ORDER BY u)
from
(
SELECT DISTINCT ord.uid AS u
FROM `uc_order_products` ord_prod, `uc_orders` ord, `uc_roles_expirations` re
WHERE ord.order_id = ord_prod.order_id
AND ord_prod.title LIKE '2012. évi%'
AND ord.uid NOT
IN (SELECT uid FROM uc_roles_expirations re)
) t