Home > database >  Online waiting for a SQL and high speed
Online waiting for a SQL and high speed

Time:10-14

-- -- -- -- -- -- -- -- -- -- table 1 -- -- -- -- -- -- --
Id cname
1 USDT
2 the ETH
3 EOS
4 HC
5 USDX
6 QTUM

-- -- -- -- -- -- -- -- -- -- table 2 -- -- -- -- -- -- -- -- --
Id name cids
1 A, 1, 2, 3
2 B 1
3 C
4 D

-- -- -- -- -- -- -- -- -- for the -- -- -- -- -- -- -- -- -- --
1 A USDT, ETH, EOS
2 B USDT
3 C
4 D

CodePudding user response:


Select
Id, b.n ame, group_concat ((select a.c name from a where id=substring_index (substring_index (biggest ids, ', '
, bb. Help_topic_id + 1), ', ', 1)))
The from
B
The join
Mysql. Help_topic bb
On bb. Help_topic_id & lt; (the length (the biggest ids) - length (the replace (biggest ids, ', ', ')) + 1) group by id

CodePudding user response:

reference 1st floor xiaomei__ response:
select
Id, b.n ame, group_concat ((select a.c name from a where id=substring_index (substring_index (biggest ids, ', '
, bb. Help_topic_id + 1), ', ', 1)))
The from
B
The join
Mysql. Help_topic bb
On bb. Help_topic_id & lt; (the length (the biggest ids) - length (the replace (biggest ids, ', ', ')) + 1) group by id
comma to cut first, then according to the cut after the id of a table of cname, reoccupy group_concat grouping merged

CodePudding user response:

The SELECT Anderson d, A.n ame, A.c ids
, REPLACE (REPLACE (GROUP_CONCAT (CASE WHEN the REPLACE (A.c ids, B.i d, biggest nname)
LIKE CONCAT (' % ', the biggest nname, '%') THEN biggest nname ELSE 'END),', ', '), ', ', ') AS cnname
The FROM tb2 A
CROSS JOIN tb1 B
GROUP BY Anderson d
The ORDER BY Anderson, d, B.i d;
  • Related