我建议采用以下方法:
SELECt client_id, array_agg(result) AS results FROM labresults GROUP BY client_id;
它的输出格式不完全相同,但是它将为您提供更快,更干净的相同信息。
如果要将结果放在单独的列中,则始终可以执行以下 *** 作:
SELECt client_id, results[1] AS result1, results[2] AS result2, results[3] AS result3FROM( SELECt client_id, array_agg(result) AS results FROM labresults GROUP BY client_id ) AS rORDER BY client_id;
尽管这显然会引入可能结果的硬编码数量。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)