Scenario introduction:
As shown in the figure below, to combine four pieces of data into one piece of data, file_url corresponds to different fields depending on the file_type.
file_utl corresponding field rules:
file_type:
4:file4_status
5:file5_status
6:file6_status
Database table data:
Data after processing:
analyze:
Rows to columns, only one piece of data, use GROUP BY. In order to splicing strings, use the aggregate function GROUP_CONCAT to get all the data, otherwise only the first data of GROUP BY is taken
Sentence pattern: CASE WHEN THEN END (AS) alias
Sentence pattern: CASE WHEN THEN ELSE END (AS) alias
Syntax: GROUP_CONCAT( file_url SEPARATOR '*') AS alias