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
- ¿Cuáles son las ventajas y desventajas de usar Google BigQuery?
- How can I export data from Google Big Query to an XLSX file?
- How do I use wildcards in Google BigQuery?
- How do I use Google Big Query to zip files?
- How do I use the YEAR function in Google BigQuery?
- How can I use Google Big Query to process XML data?
- How can I use the Google BigQuery free tier?
- How can I use Google BigQuery to wait for a query to complete?
- How do I use the UNION clause in Google BigQuery?
- How can I use Google BigQuery to retrieve data from a specific year?
See more codes...