1

我已经阅读了所有相关的问题,但无法让这个简单的事情发挥作用。我想连接这个查询的结果:

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 ',')

..并没有工作。你可以帮帮我吗?

4

2 回答 2

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:作为旁注,由于此表上缺少连接条件,此 uqery 将产生笛卡尔结果uc_roles_expirations。另一张桌子上的桌子是什么关系?

我不确定,但我认为你想要这个查询的结果,

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)
于 2013-01-31T13:32:56.410 回答
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
于 2013-01-31T13:36:40.767 回答