Search code examples
sqlgoogle-bigquerystandards

How to create subcategory SQL BIGQUERY standard


How to create subcategories with this standard sql in Bigquery. what am i missing?

i'm getting errors "Column name MVA_ID is ambiguous at [2:1]"

SELECT
MVA_ID AS MVA_ID,
ITEM_NAME AS ITEM_NAME,
PROGRAM_PMD AS PROGRAM_PMD, 
PRODUCT AS PRODUCT,
COUNTRY AS COUNTRY,
MILESTONE AS MILESTONE,
--SUBCATEGORIZATIONS Names
Category AS Category,
SubCategory AS SubCategory,
Measures AS Measures,

FROM
    --LABOR COST
    (SELECT * FROM
        (SELECT
            MVA_ID,
            ITEM_NAME,
            PROGRAM_PMD, 
            PRODUCT,
            COUNTRY,
            MILESTONE,
            "LABOR" AS Category,
            "Rate" AS SubCategory,
            SMT_IDL_RATE AS Measures,
            FROM `xxxxx`
          ) MVA
    )
 ,
    (SELECT * FROM
        (SELECT
            MVA_ID,
            ITEM_NAME,
            PROGRAM_PMD, 
            PRODUCT,
            COUNTRY,
            MILESTONE,
            "LABOR" AS Category,
            "Hours" AS SubCategory,
            SMT_LINE_TOOLING_COST AS Measures,
            FROM `xxxx`
      ) MVA
    )

i'm getting errors "Column name MVA_ID is ambiguous at [2:1]"


Solution

  • i'm getting errors "Column name MVA_ID is ambiguous at [2:1]"
    ... what am i missing?

    most likely you meant to use UNION ALL instead of CROSS JOIN (comma is a shortcut for cross join) - if you fix this above mentioned error will get away :o)