Site icon Learning & Doing

Introduction to SQL for BigQuery and Cloud SQL

SQL

“Introduction to SQL for BigQuery and Cloud SQL”

Daftar Isi

Pengantar

SQL (Structured Query Language) adalah bahasa standar untuk operasi data yang memungkinkan Anda mengajukan pertanyaan dan mendapatkan wawasan dari kumpulan data terstruktur. Ini umumnya digunakan dalam manajemen basis data dan memungkinkan Anda melakukan tugas seperti penulisan catatan transaksi ke dalam basis data relasional dan analisis data berskala petabyte.

Praktikum

Task 1. The basics of SQL

Databases and tables

SELECT and FROM

Contoh command :

SELECT USER FROM example_table
SELECT USER, SHIPPED FROM example_table

WHERE

SELECT USER FROM example_table WHERE SHIPPED='YES'

Task 2. Exploring the BigQuery console

Uploading queryable data

Google Cloud Project → bigquery-public-data
Dataset → london_bicycles
Table → cycle_hire
Table → cycle_stations

In this lab we will use the data from cycle_hire. Open the cycle_hire table, then click the Preview tab. Your page should resemble the following:

Running SELECT, FROM, and WHERE in BigQuery

SELECT end_station_name FROM `bigquery-public-data.london_bicycles.cycle_hire`;
SELECT * FROM `bigquery-public-data.london_bicycles.cycle_hire` WHERE duration>=1200;

Task 3. More SQL Keywords: GROUP BY, COUNT, AS, and ORDER BY

GROUP BY

SELECT start_station_name FROM `bigquery-public-data.london_bicycles.cycle_hire` GROUP BY start_station_name;

COUNT

SELECT start_station_name, COUNT(*) FROM `bigquery-public-data.london_bicycles.cycle_hire` GROUP BY start_station_name;

AS

SELECT start_station_name, COUNT(*) AS num_starts FROM `bigquery-public-data.london_bicycles.cycle_hire` GROUP BY start_station_name;

ORDER BY

SELECT start_station_name, COUNT(*) AS num FROM `bigquery-public-data.london_bicycles.cycle_hire` GROUP BY start_station_name ORDER BY start_station_name;
SELECT start_station_name, COUNT(*) AS num FROM `bigquery-public-data.london_bicycles.cycle_hire` GROUP BY start_station_name ORDER BY num;
SELECT start_station_name, COUNT(*) AS num FROM `bigquery-public-data.london_bicycles.cycle_hire` GROUP BY start_station_name ORDER BY num DESC;

Task 4. Working with Cloud SQL

Exporting queries as CSV files

SELECT start_station_name, COUNT(*) AS num FROM `bigquery-public-data.london_bicycles.cycle_hire` GROUP BY start_station_name ORDER BY num DESC;

Upload CSV files to Cloud Storage

Task 5. Create a Cloud SQL instance

Task 6. New queries in Cloud SQL

CREATE keyword (databases and tables)

https://shell.cloud.google.com/?show=terminal
gcloud config set project [PROJECT_ID]

Create a database in Cloud Shell

gcloud auth login --no-launch-browser
gcloud config set project [PROJECT_ID]
gcloud sql connect qwiklabs-demo --user=root --quiet
CREATE DATABASE bike;
USE bike;
CREATE TABLE london1 (start_station_name VARCHAR(255), num INT);

USE bike;
CREATE TABLE london2 (end_station_name VARCHAR(255), num INT);

SELECT * FROM london1;
SELECT * FROM london2;

Upload CSV files to tables

Penutup

Sahabat Blog Learning & Doing demikianlah penjelasan mengenai Introduction to SQL for BigQuery and Cloud SQL. Semoga Bermanfaat . Sampai ketemu lagi di postingan berikut nya.

Exit mobile version