简体   繁体   English

如何在bigquery中选择不同的值(多个值)?

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

相关问题 如何仅 select *列*具有多个不同的值? - How to select only *columns* with more than one distinct value? 如何在 SQL 中选择具有 1 个以上不同值的行? - How to select rows that have more than 1 distinct values in SQL? 在 Oracle SQL 中,如何找到一列中的所有值,而另一列中存在多个不同值 - In Oracle SQL how can i find all values in one column for which in another column exist more than one distinct value 选择DISTINCT值,其中where子句在内部联接上返回多个结果 - Select DISTINCT values with where clause returning more than one result on inner join 如何在不止一列上计算差异 - How to COUNT DISTINCT on more than one column 当同一表的另一列中存在多于1个不同值时,用于从一列中计算不同值的SQL查询 - SQL Query for Counting Distinct Values From One Column When More Than 1 Distinct Value exists in Another Column in the same table 休眠选择不同的值,按一个值排序 - hibernate select distinct values order by one value 选择用户在mysql中有多个不同的记录 - select users have more than one distinct records in mysql select 通过返回多于一行来区分 + 分组 - select distinct + group by returning more than one row 选择具有多于一个独立列的整行 - Select entire row with more than one distinct column
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM