SQL 行转列

时间:2024-03-04 20:47:59
  1. MySQL
    mysql换行使用'\n'
SELECT
	pic_business_id,
	GROUP_CONCAT( '\n类型', ':', pic_med_type_name, ',金额', pic_cost ) 
FROM
	`sl_patient_item_cost` 
GROUP BY
	pic_business_id

在这里插入图片描述
2. Oracle
oracle换行使用CHR( 10 )

SELECT
    MEDICAL_RECORD_ID,
    IN_NUMBER,
    NAME,
    REPLACE( wmsys.wm_concat ( CHR( 10 ) || FIEID || ':' || ERRO || ';'  ),';,' , ';') as ERRO
FROM
    "MR_IN_ERROR"
WHERE FILE_ID = #{fileId}
GROUP BY
    MEDICAL_RECORD_ID, IN_NUMBER,NAME

在这里插入图片描述