Append two tables - Union not working in SQL (Teradata) -


i'm beginner sql. i'm using teradata. we're trying pull data compare actuals versus forecast.

here code:

select  'actuals' fc_version, a.tra_fiscal_year fiscal_year, a.tra_fiscal_week fiscal_week, a.tra_allocation_category_code category, a.tra_grand_pricing_sales_channel grandparent_channel, d.fc_prod_id, coalesce( case when a.tra_ticket_product_code 'a%' 'total' else null end,  case when a.tra_grand_pricing_sales_channel = 'inmkt' 'in market' else 'all other' end ) fc_sales_channel,  sum(a.tra_ticket_quantity) units_sold,  ((pd_plan_forecast_db.adm_rev_detail left outer join pd_plan_forecast_db.adm_rev_prod_code_to_fc_id b on (a.tra_ticket_product_code = b.product_code)) left outer join pd_plan_forecast_db.adm_rev_ticket_code_to_fc_id c on (a.tra_ticket_code = c.ticket_code) left outer join pd_plan_forecast_db.adm_rev_fc_prod_info d on (coalesce(b.fc_prod_id, c.fc_prod_id) = d.fc_prod_id))  group 1, 2, 3, 4, 5, 6, 7  union  select fc_version, fiscal_year, fiscal_week, category, null grandparent_channel, fc_prod_id, fc_sales_channel, sum(units_sold) units_sold pd_plan_forecast_db.adm_rev_fc fiscal_year = 2017 , fiscal_week = 1 group 1,2,3,4,5,6,7 

if paste first part before union, has correct result. likewise second part after union.

but entire code gives error: select failed. [3654] corresponding select-list expressions incompatible.

here general idea of tables i'm using. enter image description here

you must have same number of columns in both parts (top , bottom) same data type.

as far can count there 9 columns in top query , 8 in bottom one.

upd: fix according author convert null empty string in below query.


Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -