Home > database >  Ask ace to help me to optimize the SQL statement.
Ask ace to help me to optimize the SQL statement.

Time:01-09

There is a server list, a server service table,
Goal is to query the server list, and connect the server running on the services for string as the value of a column,

Server table (server)


The service table (service)


I suck write SQL statements,

 
Select a t1. *, t2. The service from r_server t1 left join
(select a_id, GROUP_CONCAT (b_n) as "service" from
(SELECT as "a_id," Anderson d b.i d as "b_id", b.n ame as "b_n" FROM "r_server left a" join "r_serverservice" b on Anderson, d=b.s erver_id) temp
Group by a_id) t2
On t1. Id=t2. A_id


The results of the query



thank you so much for bosses.


CodePudding user response:

 
Select a t1. *, t2. The service from r_server t1 left join
(select a_id, GROUP_CONCAT (b_n) as "service" from
(SELECT as "a_id," Anderson d b.i d as "b_id", b.n ame as "b_n
"FROM "r_server" a left join "r_serverservice" b on Anderson, d=b.s erver_id) temp
Group by a_id) t2
On t1. Id=t2. A_id
  • Related