Thanks for the sql.
However, why not going through the next step and return the index details at the same time...
Something like
SELECT TOP 20 mid.statement as table_name, equality_columns, inequality_columns, included_columns
, CAST(index_advantage AS INT) AS index_advantage -- cast to hint just to make it more readable
FROM (
SELECT (user_seeks+user_scans) * avg_total_user_cost * (avg_user_impact * 0.01) as index_advantage
, migs.group_handle
FROM sys.dm_db_missing_index_group_stats migs
) as migs_adv,
sys.dm_db_missing_index_groups mig,
sys.dm_db_missing_index_details mid
WHERE migs_adv.group_handle = mig.index_group_handle
AND mig.index_handle = mid.index_handle
ORDER BY index_advantage DESC
😉