答案 0 :(得分:1)
如何使用标准sql语法在任何支持分析功能的数据库上旋转/转置/交叉表数据,尽管我还假设您的评论完全可以是任何文本:
SELECT
invoiceno,
MAX(case when rn = 1 then remark end) as remark1,
MAX(case when rn = 2 then remark end) as remark2,
MAX(case when rn = 3 then remark end) as remark3/*,
--add as many lines as you need columns
MAX(case when rn = X then remark end) as remarkX
*/
FROM
(SELECT invoiceno, remark, row_number() over(partition by invoiceno order by remark) rn FROM table) t
GROUP BY invoiceno