[英]How to select distinct values (more than one value) in bigquery?
I have to make a query where I get the number of unique values from a database.我必须进行查询,从数据库中获取唯一值的数量。 In this database(type of jobs).
在这个数据库中(工作类型)。 In the column "jobs" there are strings like "doctor, lawyer" or "paramedic, banker, teacher".
在“工作”列中,有诸如“医生、律师”或“护理人员、银行家、教师”之类的字符串。 When I do the query:
当我做查询时:
SELECT DISTINCT jobs FROM Type_Of_Jobs从 Type_Of_Jobs 中选择 DISTINCT 作业
I get some rows that only include one string, but I need combinations (so not just one value) and I need to be able to return # of those unique combinations.我得到一些只包含一个字符串的行,但我需要组合(所以不仅仅是一个值)并且我需要能够返回这些唯一组合的#。 How do I do this in bigquery?
我如何在 bigquery 中做到这一点? Thank you!
谢谢!
Use split()
and unnest()
:使用
split()
和unnest()
:
select job, count(*)
from type_of_jobs tj cross join
unnest(split(jobs, ',')) job
group by job;
Are you looking for a simple count for each combination of job string as it is or you want each combination to be split into the individual job and distinct count of the individual job?您是按原样为作业字符串的每个组合寻找简单的计数,还是希望将每个组合拆分为单个作业和单个作业的不同计数?
For each combination of job string as it is:对于作业字符串的每个组合,原样:
SELECT jobs, count(*) count
FROM Type_Of_Jobs
group by jobs
For a distinct count of the individual job, look at Gordon's answer.对于单个工作的不同计数,请查看戈登的回答。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.