简体   繁体   English

BigQuery SQL - 我怎么知道最小值、最大值和平均值?

[英]BigQuery SQL - how can i know the min, max and avg?

Here's the output:这是 output:

enter image description here在此处输入图像描述

Hello, i would like to know if it's possible to know the min, max and average "year_birth" other than looking for it manually?您好,我想知道除了手动查找之外是否有可能知道最小值、最大值和平均值“year_birth”?

Here's my following code (it might be super bad, it's because i'm beginning with SQL)这是我的以下代码(它可能非常糟糕,因为我是从 SQL 开始的)

 WITH clean_profils as( SELECT *, REPLACE(Marital_Status,"Alone","Single") AS Clean_Marital_Status FROM `neoma-bdd.data.profils` WHERE Year_Birth > 1940 AND Marital_Status <> "YOLO" and Marital_Status <> "Absurd" AND Income IS NOT null ) SELECT clean_profils.id, Year_Birth, Income, Kidhome, Teenhome, Dt_Customer, Clean_Marital_Status, MntWines + MntFruits + MntMeatProducts + MntFishProducts + MntSweetProducts + MntGoldProds AS ALL_PURCHASES, FROM `neoma-bdd.data.purchases` INNER JOIN clean_profils ON `neoma-bdd.data.purchases`.id = clean_profils.id ORDER by ALL_PURCHASES LIMIT 560



Bonus question, i'm doing a segmentation as follow : 

Quartile 1 : 1 rows to 559,75 rows
Quartile 2 : 559,75 rows to 1119 rows
Médiane : 1119,5 
Quartile 3 : 1120 rows to 1679,75 rows
Quartile 4 : 1679,75 rows to 2240 rows

how can i select only the 560 to 1119 rows based on "All_Purchases"

i tried self joining but it didn't help me at all :/ 

It seems a simple question看似简单的问题

SELECT AVG(Year_Birth) as Average

should provide the mean应该提供平均值

 SELECT APPROX_QUANTILES(Year_Birth, 2) AS approx_quantiles

or if there are nulls in your data或者如果您的数据中有空值

SELECT FORMAT("%T", APPROX_QUANTILES(Year_Birth, 2 RESPECT NULLS)) AS approx_quantiles

should provide you with a min, median and max应该为您提供最小值、中值和最大值

SELECT
  APPROX_TOP_COUNT(Year_Birth,1) AS mode

should provide you with the mode应该为您提供模式

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

相关问题 如何在 sql 中获取最大日期的最小值? - How to get min value at max date in sql? 我如何将字符串字段取消嵌套到 SQL BIGQUERY 中的行中 - How can i unnest a string field into rows in SQL BIGQUERY 如何为每个客户在 BigQuery 中以宽格式更改 label 获取正确的最小、最大日期? - How to get correct min, max date for each customer's changing label in wide format in BigQuery? 为什么 Max、Min、Avg 统计数据在 Cloudwatch 中的 5 分钟指标上有不同的结果? - Why does Max, Min, Avg statistics have different results on a 5 min metric in Cloudwatch? 如何在大查询中根据时间戳最小最大值查询按某些类别分组的两个值的减法 - How can I query subtraction of two values grouped by certain categories based on timestamp min max on big query 如何将带有嵌套分隔符的列拆分为 Bigquery SQL 中的结构列表? - How can I split a column with nested delimiters into a list of STRUCTs in Bigquery SQL? 如何更改 BigQuery 中的项目 - How can I change the project in BigQuery 如何在 BigQuery SQL 中添加 arrays? - How do I add arrays in BigQuery SQL? 如何在 BigQuery 中创建外部数据源并连接到 composer cloud sql? - How can I create external data source in BigQuery and connect to composer cloud sql? 如何使用 BigQuery SQL 将 Java 代码注册为 UDF 或自定义 function? - How can I register Java code as UDF or custom function with BigQuery SQL?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM