Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- BEGIN
- DROP TABLE IF EXISTS attendeesWithCustomFields;
- SET @SQL = NULL;
- SELECT GROUP_CONCAT( DISTINCT
- CONCAT(
- 'MIN(CASE WHEN cf.field_name = ''',
- field_name,
- ''' THEN cf.field_value END) AS ',
- field_name
- )
- ) INTO @SQL
- FROM custom_fields;
- SET @SQL = CONCAT( 'CREATE TABLE attendeesWithCustomFields
- SELECT a.* , ', @SQL , '
- FROM attendees a
- LEFT JOIN custom_fields AS cf
- ON cf.event_id = a.event_id AND cf.investor_id = a.investor_id
- GROUP BY a.event_id, a.investor_id ' );
- PREPARE stmt FROM @SQL;
- EXECUTE stmt;
- DEALLOCATE PREPARE stmt;
- END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement