繁体   English   中英

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

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

这是 output:

在此处输入图像描述

您好,我想知道除了手动查找之外是否有可能知道最小值、最大值和平均值“year_birth”?

这是我的以下代码(它可能非常糟糕,因为我是从 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 :/ 

看似简单的问题

SELECT AVG(Year_Birth) as Average

应该提供平均值

 SELECT APPROX_QUANTILES(Year_Birth, 2) AS approx_quantiles

或者如果您的数据中有空值

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

应该为您提供最小值、中值和最大值

SELECT
  APPROX_TOP_COUNT(Year_Birth,1) AS mode

应该为您提供模式

暂无
暂无

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

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