如何在bigquery中不使用键连接多个表

问题描述 投票:-1回答:1

表名和模式

    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)) 

在结构中得到的结果,这不能用于我正在 excepting 的 schema。请帮助我解决这些问题。

google-cloud-platform google-bigquery data-mining
1个回答
1
投票
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))

这解决了我的问题

© www.soinside.com 2019 - 2024. All rights reserved.