Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bigquery select distinct values

Tags:

How to select distinct values in Google Bigquery?

Query:

SELECT DISTINCT cc_info
FROM user
WHERE date = ?

Thanks!

like image 382
zdc Avatar asked Jun 03 '15 05:06

zdc


People also ask

What does distinct do in BigQuery?

A SELECT DISTINCT statement discards duplicate rows and returns only the remaining rows. SELECT DISTINCT cannot return columns of the following types: STRUCT. ARRAY.

WHAT IS WITH clause in BigQuery?

The WITH clause contains one or more common table expressions (CTEs). Each CTE binds the results of a subquery to a table name, which can be used elsewhere in the same query expression. BigQuery does not materialize the results of non-recursive CTEs within the WITH clause.


2 Answers

SELECT cc_info
FROM user
WHERE date = ?
GROUP BY cc_info
like image 56
tning Avatar answered Oct 12 '22 14:10

tning


Simply use group by,

SELECT cc_info
FROM user
WHERE date = ?
GROUP BY cc_info

If you want to COUNT over DISTINCT values you can use,

SELECT COUNT(DISTINCT cc_info)
FROM user
WHERE date = ?
like image 23
Deepak Mittal Avatar answered Oct 12 '22 13:10

Deepak Mittal