正在搜索 GROUP_CONCAT 个值?
Searching through the GROUP_CONCAT values?
如果我的组连接中有 5 个名字 returned,是否可以通过某种方式进一步限制 returned table?例如,如果我只想查看名称为“Assembly”的公司,并且如果我在 AND
中使用它
"AND cell_name = 'Assembly'"
然后我的组 concat 将只显示 Assembly,而不显示其余 5 个名称,尽管我希望这样。
SELECT
GROUP_CONCAT(DISTINCT cell_name ORDER BY cell_name ASC) as Cell,
integrator_country as Country,
integrator_name as Name
FROM sme_cells_integrator_link
INNER JOIN sme_cells ON
(sme_cells.id = sme_cells_integrator_link.fk_cells_id)
INNER JOIN sme_integrator ON
(sme_integrator.id = sme_cells_integrator_link.fk_integrator_id)
WHERE integrator_country = 'Denmark'
GROUP BY integrator_name
我想要的是 return 已选择的订单类型,但仍然显示公司拥有的所有订单,就像 GROUP_CONCAT 通常那样。
没有我的 AND,returned 数据看起来有点像这样:
+-----------------------------------------------------+---------+--------------+
| Assembly,Packaging | Denmark | Firm 1 |
| Packaging,Palletizing | Denmark | Firm 2 |
| Handling | Denmark | Firm 3 |
| Grinding / Finishing,Handling,Packaging,Palletizing | Denmark | Firm 4 |
+-----------------------------------------------------+---------+--------------+
用我的 AND,它看起来像这样:
+----------+-----------+--------+
| Assembly | Denmark | Firm 1 |
+----------+-----------+--------+
我希望它看起来像这样:
+--------------------+-----------+-------+
| Assembly,Packaging | Denmark | Firm 1|
+--------------------+-----------+-------+
我们需要你的表而不是结果,然后我们可以让你成为子选择。
但另一个快速而肮脏的选择是拥有:
SELECT
GROUP_CONCAT(DISTINCT cell_name ORDER BY cell_name ASC) as Cell,
integrator_country as Country,
integrator_name as Name
FROM sme_cells_integrator_link
INNER JOIN sme_cells ON
(sme_cells.id = sme_cells_integrator_link.fk_cells_id)
INNER JOIN sme_integrator ON
(sme_integrator.id = sme_cells_integrator_link.fk_integrator_id)
WHERE integrator_country = 'Denmark'
GROUP BY integrator_name
HAVING Cell LIKE '%Assembly%'
如您所见,使用此解决方案时您会遇到名称相似的问题。
如果我的组连接中有 5 个名字 returned,是否可以通过某种方式进一步限制 returned table?例如,如果我只想查看名称为“Assembly”的公司,并且如果我在 AND
中使用它"AND cell_name = 'Assembly'"
然后我的组 concat 将只显示 Assembly,而不显示其余 5 个名称,尽管我希望这样。
SELECT
GROUP_CONCAT(DISTINCT cell_name ORDER BY cell_name ASC) as Cell,
integrator_country as Country,
integrator_name as Name
FROM sme_cells_integrator_link
INNER JOIN sme_cells ON
(sme_cells.id = sme_cells_integrator_link.fk_cells_id)
INNER JOIN sme_integrator ON
(sme_integrator.id = sme_cells_integrator_link.fk_integrator_id)
WHERE integrator_country = 'Denmark'
GROUP BY integrator_name
我想要的是 return 已选择的订单类型,但仍然显示公司拥有的所有订单,就像 GROUP_CONCAT 通常那样。
没有我的 AND,returned 数据看起来有点像这样:
+-----------------------------------------------------+---------+--------------+
| Assembly,Packaging | Denmark | Firm 1 |
| Packaging,Palletizing | Denmark | Firm 2 |
| Handling | Denmark | Firm 3 |
| Grinding / Finishing,Handling,Packaging,Palletizing | Denmark | Firm 4 |
+-----------------------------------------------------+---------+--------------+
用我的 AND,它看起来像这样:
+----------+-----------+--------+
| Assembly | Denmark | Firm 1 |
+----------+-----------+--------+
我希望它看起来像这样:
+--------------------+-----------+-------+
| Assembly,Packaging | Denmark | Firm 1|
+--------------------+-----------+-------+
我们需要你的表而不是结果,然后我们可以让你成为子选择。
但另一个快速而肮脏的选择是拥有:
SELECT
GROUP_CONCAT(DISTINCT cell_name ORDER BY cell_name ASC) as Cell,
integrator_country as Country,
integrator_name as Name
FROM sme_cells_integrator_link
INNER JOIN sme_cells ON
(sme_cells.id = sme_cells_integrator_link.fk_cells_id)
INNER JOIN sme_integrator ON
(sme_integrator.id = sme_cells_integrator_link.fk_integrator_id)
WHERE integrator_country = 'Denmark'
GROUP BY integrator_name
HAVING Cell LIKE '%Assembly%'
如您所见,使用此解决方案时您会遇到名称相似的问题。