How to create dimension and fact table from another table