Как присоединиться к нескольким таблицам без использования ключа в bigquery - PullRequest
0 голосов
/ 07 мая 2020

Имя и схема таблицы

    Table 1:student table
    column name : student_name, student_address, student_mark
    Table 2:staff table
    Column name: Staff_name, Staff_address, Staff_age, staff_class
    Table 3: alumni table
    Column name: alumni_name, alumni_address, alumni_year_passing, Alumni_marks, alumni_work_details

Мое намерение сделать одну таблицу, содержащую нулевое количество столбцов, представит все три таблицы с использованием Bigquery. Схема для построения нулевой таблицы

student_name_null_pct float,
student_address_null int, 
student_address_null_pct float,
student_mark_null int,
Staff_name_null int,
Staff_address_null int, 
staff_class_null int,
alumni_name_null int, 
alumni_address_null int, 
alumni_year_passing_null int

Используемая структура в bigquery

SELECT
  ( (
    SELECT
      AS STRUCT student_name_null,
      ROUND(SAFE_DIVIDE(student_name_null,
          total_rows), 5) AS student_name_null_pct,
      student_address,
      ROUND(SAFE_DIVIDE(student_address,
          total_rows), 5) AS student_address_pct
    FROM (
      SELECT
        CURRENT_DATE() AS date,
        COUNT(*) AS total_rows,
        COUNTIF(student.student_name IS NULL) AS student_name_null,
        COUNTIF(distributors.student_address IS NULL) AS student_address,
        COUNTIF(distributors.student_mark IS NULL) AS student_mark

      FROM
        `school.student_table` AS student)),
    (
    SELECT
      AS STRUCT total_rows_staff,
      Staff_name,
      ROUND(SAFE_DIVIDE(Staff_name,
          total_rows_staff), 5) AS Staff_name_pct,
      brand_title,
      ROUND(SAFE_DIVIDE(Staff_address,
          total_rows_staff), 5) AS Staff_address_pct

    FROM (
      SELECT
        COUNT(*) AS total_rows_staff,
        COUNTIF(products.Staff_name IS NULL) AS Staff_name,
        COUNTIF(products.Staff_address IS NULL) AS Staff_address,

      FROM
        `school.staff_table` AS staff)) 

Получение результата в структуре, это не может использоваться для схемы, которую я исключаю. Пожалуйста, помогите мне решить проблемы.

1 Ответ

1 голос
/ 07 мая 2020
SELECT
  CURRENTDATE() AS date,
  student_name_null,
  ROUND(SAFE_DIVIDE(student_name_null,
      total_rows), 5) AS student_name_null_pct,
  student_address,....
FROM (
  SELECT
    COUNT(*) AS total_rows,
    COUNTIF(student.student_name IS NULL) AS student_name_null,
    COUNTIF(distributors.student_address IS NULL) AS student_address,
    COUNTIF(distributors.student_mark IS NULL) AS student_mark
  FROM
    `school.student_table` AS student),
  (
  SELECT
    COUNT(*) AS total_rows_staff,
    COUNTIF(products.Staff_name IS NULL) AS Staff_name,
    COUNTIF(products.Staff_address IS NULL) AS Staff_address,
  FROM
    `school.staff_table` AS staff))

Это решило мои проблемы

...