我有这个SQL查询:
SELECT pokemon.ID,
pokemon.internalName,
pokemon.name,
at1.internalName as type1,
mat1.internalName as megaType1,
at2.internalName as type2,
mat2.internalName as megaType2,
pokemon.baseStats,
pokemon.megaBaseStats,
pokemon.genderRate,
pokemon.growthRate,
pokemon.baseEXP,
pokemon.effortPoints,
GROUP_CONCAT(DISTINCT ab.internalName SEPARATOR ",") AS abilities,
GROUP_CONCAT(DISTINCT mab.internalName SEPARATOR ",") AS megaAbilities,
GROUP_CONCAT(DISTINCT hab.internalName SEPARATOR ",") AS hiddenAbilities,
pokemon.movesByLevelingID,
pokemon.eggMovesID,
egg1.internalName as eggGroup1,
egg2.internalName as eggGroup2,
pokemon.stepsToHatch,
pokemon.height,
pokemon.megaHeight,
pokemon.weight,
pokemon.megaWeight,
colors.name as color,
pokemon.kind,
pokemon.form,
pokemon.pokedex,
pokemon.evolutionsID,
prevo.internalName as prevolution,
megaevo.internalName as megaEvolution,
mgstn.internalName as megaStone
FROM pokemon
LEFT JOIN attackTypes at1
ON pokemon.type1ID=at1.ID
LEFT JOIN attackTypes mat1
ON pokemon.megaType1ID=mat1.ID
LEFT JOIN attackTypes at2
ON pokemon.type2ID=at2.ID
LEFT JOIN attackTypes mat2
ON pokemon.megaType2ID=mat2.ID
LEFT JOIN abilities ab
ON FIND_IN_SET(ab.ID, pokemon.abilitiesID)
LEFT JOIN abilities mab
ON FIND_IN_SET(mab.ID, pokemon.megaAbilitiesID)
LEFT JOIN abilities hab
ON FIND_IN_SET(hab.ID, pokemon.hiddenAbilityID)
LEFT JOIN eggGroups egg1
ON pokemon.eggGroup1ID=egg1.ID
LEFT JOIN eggGroups egg2
ON pokemon.eggGroup2ID=egg2.ID
LEFT JOIN colors
ON pokemon.colorID=colors.ID
LEFT JOIN pokemon prevo
ON pokemon.prevolutionID=prevo.ID
LEFT JOIN pokemon megaevo
ON pokemon.megaEvolutionID=megaevo.ID
LEFT JOIN items mgstn
ON pokemon.megaStoneID=mgstn.ID
WHERE pokemon.internalName = 'CHARIZARD'
GROUP BY pokemon.ID
这将返回我想要的所有数据,除了我输入GROUP_CONCAT的列,它确实从正确的表中拾取结果,但它向后显示信息。如何让它显示首先获取的第一个ID?
澄清:
表: 1 Apple 2橙色 3梨 4新西兰人 5香蕉
柱: 1,2,4
它将返回: 猕猴桃,橙,苹果
感谢您的时间和精力,非常感谢!
答案 0 :(得分:-1)
order by
在Impala中的group_concat
内无效,因为数据跨节点传播。
因此,使用限制XXX(确保它不低于您拥有的行数),以便所有数据都转到一个数据节点,然后group_concat将起作用:)
示例:
select member, group_concat(event,';')
from (
select member, event
from table
order by time
limit 10000000000
)
group by 1