sql - BigQuery 中的潜在客户和分析功能
问题描述
假设我的桌子是这样的
我正在尝试使用此信息修改我的表格
我添加了两列,其中列WhenWasLastBasicSubjectDone
将让您知道学生在哪个学期完成了他最新的基础课程(按学期排序)。另一栏TotalBasicSubjectsDoneTillNow
解释了学生到目前为止完成了多少次基础课程(主题)(按学期排序)?
我认为使用 Joins 和 UDF 很容易解决这个问题,但我想利用 BigQuery 中现有分析函数的强大功能并在没有连接的情况下解决它。
解决方案
您可以为此使用窗口函数——假设您有一个指定排序的列。让我假设该列是semester
:
select t.*,
max( case when subject = 'Basic' then semester end ) over (partition by student order by semester end) as lastbasic,
sum( case when subject = 'Basic' then 1 else 0 end ) over (partition by student order by semester end) as numbasictillnow
from t
推荐阅读
- firebase - Firestore 查询流和获取之间的区别?
- java - 如何将自定义工具提示添加到 JtextField?
- ffmpeg - 输出流中的非单调 DTS 0:1
- laravel - Laravel - 图片上传在服务器上不起作用
- wordpress - 比较WordPress中的用户名和自定义字段
- python-3.x - Google team drive 和 google colaboratory 下载/上传文件
- angular - 在角度 4 中加载更多按钮
- wordpress - WordPress 厚盒响应式
- google-analytics - 分析跟踪,相同的 URL 不同的 ID
- ios - 从 Swift 中的模型类中提取值