这是向我返回左栏中区域ID的输出,右栏中的region_name以及属于该区域的国家但我想让国家缩进几个空格的查询。
SELECT region_id, region_name
FROM
(
SELECT r.region_id, r.region_name, 0 AS ent
FROM regions r
UNION ALL
SELECT r.region_id, c.country_name, 1 AS ent
FROM regions r
INNER JOIN countries c
ON r.region_id = c.region_id
)
ORDER BY region_id, ent, region_name;
1 Europe 1 Belgium 1 Denmark 1 France 1 Germany 1 Italy 1 Netherlands 1 Switzerland 1 United Kingdom 2 Americas 2 Argentina 2 Brazil 2 Canada 2 Mexico 2 United States of America
答案 0 :(得分:1)
这应该有效:
SELECT r.region_id, CONCAT(' ', c.country_name), 1 AS ent
您可能需要为组合字段添加AS
子句以将它们组合在一起。