I have two rows in a table. I want to add in a third row which holds the total value.
My table is
SELECT
CONTROLLED_PERCENTAGE, EL_CLIENT_ID, ID,
PERC_ADJ_UNITS_RECEIVED, PHY_DIG_OR_TOTAL, RECORDING_ID,
SUM_UNITS_RECEIVED, UNIT_TYPE
FROM EL_CLIENT_REC_UNITS;
I will have the EL_CLIENT_ID, UNIT_TYPE, PHY_DIG_OR_TOTAL will be ‘PHY’ or ‘DIG’ and I am looking to get the total. I want to add up the two record’s SUM_UNITS_RECEIVED and PERC_UNITS_RECEIVED where the UNIT_TYPES, EL_CLIENT_ID and RECORDING_IDs are the same. I then want to insert this as a new row with the same UNIT_TYPE, RECORDING_ID but this time have PHY_DIG_OR_TOTAL set to ‘TOTAL’;
Try something like this:
Try to google for
GROUP BYSQL statement to learn more about this statement.