简体   繁体   English

迭代列以查看检查 Bigquery 中的某些条件

[英]Iterating over a column to see check certain conditions in Bigquery

I am using Big query to extract results from employee learning table.我正在使用大查询从员工学习表中提取结果。 I need to figure out if an employee has completed a set of courses for a department.我需要弄清楚员工是否完成了部门的一组课程。 For example if an employee complete all of these three courses say, course 100, course 200 and course 300, they can be classified as as compliant else They are non-compliant.例如,如果一名员工完成了所有这三门课程,比如课程 100、课程 200 和课程 300,他们可以被归类为合规,否则他们是不合规的。 I have created a dummy example of how my data is structured, unfortunately due to organization policy I cant share more information.我创建了一个虚拟示例来说明我的数据是如何构建的,不幸的是,由于组织政策,我无法分享更多信息。 Problem statement.问题陈述。 Say employee who has completed course 100,200,300 They are compliant in Bakery else they are non-complaint.说已经完成课程 100,200,300 的员工他们在面包店是合规的,否则他们是非投诉的。 Employee must complete all three courses to be compliant.员工必须完成所有三门课程才能合规。

Employee who has completed course 100 and 300 They are compliant in Fruit & Veg else they are non-complaint.已完成课程 100 和 300 的员工 他们在水果和蔬菜方面合规,否则他们不抱怨。 They must complete above mention two courses to be compliant.他们必须完成上述两门课程才能合规。

Employee who has completed course 75,85,95 They are compliant in Grocery else non-compliant.已完成课程 75、85、95 的员工他们符合杂货业的要求,其他不符合要求。 Same here they must have done three courses so that they can be compliant.同样在这里,他们必须完成三门课程才能合规。

Employee who has completed 101 and 102 They are compliant in Nighfill else non-compliant.完成 101 和 102 的员工他们在 Nighfill 中合规,否则不合规。

Please note employee must complete all the sets to be compliant in relevant categories请注意,员工必须完成所有设置才能符合相关类别的要求

Employee course 1 100 1 101 1 200 1 300 1 300 1 400 2 100 2 200 3 100 3 200 3 300 4 75 4 85 4 95 4 105 4 115 4 125员工课程 1 100 1 101 1 200 1 300 1 300 1 400 2 100 2 200 3 100 3 200 3 300 4 75 4 85 4 95 4 105 4 115 4 125
5 200 5 200 5 100 5 100 5 100 5 300 5 300 6 100 7 100 8 300 8 200 8 100 8 101 8 102 9 100 9 200 9 300 5 200 5 200 5 100 5 100 5 100 5 300 5 300 6 100 7 100 8 300 8 200 8 100 8 101 8 102 9 100 9 200 9 300

Structure of Data数据结构

I am still thinking about the solution.我仍在考虑解决方案。

Consider below approach考虑以下方法

select Employee, 
  ifnull(array_length(split(string_agg(distinct if(course in (100,200,300), '' || course, null)))), 0) = 3 isBakeyCompliant,
  ifnull(array_length(split(string_agg(distinct if(course in (100,300) and not course in (200), '' || course, null)))), 0) = 2 isFruitVegCompliant,
  ifnull(array_length(split(string_agg(distinct if(course in (75,85,95), '' || course, null)))), 0) = 3 isGroceryCompliant,
  ifnull(array_length(split(string_agg(distinct if(course in (101,102), '' || course, null)))), 0) = 3 isNighfillCompliant,
from your_table
group by Employee    

with output output

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM