google-big-queryHow can I use Google Big Query to split data?
Google BigQuery allows you to split data into multiple tables using the CREATE OR REPLACE TABLE
statement. The syntax is as follows:
CREATE OR REPLACE TABLE <destination_table>
AS
SELECT *
FROM <source_table>
WHERE <condition>
The <destination_table>
is the name of the table that will be created with the data that satisfies the condition. The <source_table>
is the name of the table from which the data will be taken. The <condition>
is an expression that determines which rows of the source table will be included in the destination table.
For example, to split the table users
into two tables users_male
and users_female
based on the gender field, the following query can be used:
CREATE OR REPLACE TABLE users_male
AS
SELECT *
FROM users
WHERE gender = 'male'
CREATE OR REPLACE TABLE users_female
AS
SELECT *
FROM users
WHERE gender = 'female'
This will create two new tables, users_male
and users_female
, with the data from the users
table that satisfy the specified conditions.
Code explanation
**
CREATE OR REPLACE TABLE
: statement to create a new table or replace an existing oneSELECT *
: statement to select all columns from the source tableFROM <source_table>
: statement to specify the source tableWHERE <condition>
: statement to specify the condition for the rows to be included in the table
## Helpful links
More of Google Big Query
- How can I use Google Big Query to count the number of zeros in a given dataset?
- How do I use Google Big Query to zip files?
- How do I set up a Google Big Query zone?
- How can I use Google Big Query to process XML data?
- How do I query Google BigQuery using XML?
- How can I use Google Big Query with MicroStrategy?
- ¿Cuáles son las ventajas y desventajas de usar Google BigQuery?
- How can I use Google BigQuery to retrieve data from a specific year?
- How do I use the YEAR function in Google BigQuery?
- How do I use Google Big Query with Excel?
See more codes...