SQL
to communicate with the serverCheck if there’s any update first
Install postgreSQL: brew install postgresql
Start: brew services start postgresql
createdb
'db_name'
psql
'db_name'
CREATE TABLE
table_name (column_1 datatype, column_2 datatype, column_3 datatype)
\d
\q
INSERT INTO
table_name (column_1, column_2, column_3) VALUES (value_1, 'value_2', value_3);
SELECT
column FROM
table_name
SELECT
column_name FROM
table_name*
- grab the entire columnsSELECT * FROM users **WHERE** name **LIKE** 'A%'
- name starts with ASELECE * FROM users **ORDER BY** score **DESC**
Add another column to a existing table: ALTER TABLE
table_name ADD
column_name datatype;
Update the information: UPDATE
table_name SET
some_column = some value WHERE
some_column = some_value;
AVG()
- average:AVG 函數返回數值列的平均值。NULL 值不包括在計算中。
SUM()
- sum
COUNT()
- count:函數用於返回匹配指定條件的行數。
MAX()
- max:函數返回指定列的最大值,NULL值不包括在計算中MIN()
- min:函數返回的指定列的最小值,NULL值不包括在計算中Delete
Drop table
To learn more about SQL and do some fun exercises, follow this free tutorial which gives some fun interactive exercises for you: https://www.khanacademy.org/computing/computer-programming/sql