[英]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.