The query results of the Postgresql database return 6 columns. The first column is the grouping column, the second column is the Value column in the group, and the 3rd to 6th columns are the Key columns in the group. Only one Key field of each record has a value, and the other Key fields are empty. The location of the key value of each record is uncertain.
Now we need to keep the grouping columns unchanged, convert the details within the group from rows to columns, convert the non-null Key column values to new column names, and convert the Value column values to new column values.
Sound pressure level code:
A1: Query the database through JDBC.
A2: Use the pivot function to convert this set of records from rows to columns. The first parameter is the grouping column, the second parameter is the column name of Key, and the ifn function takes the first non-empty member in the set. The third parameter is the value column.