如何從SQL數據庫表中獲取數據

您可以使用SELECT命令從表中獲取數據。

獲取所有行和列:

SELECT * FROM people;
age | name
-----+--------
37  | Flavio
8   | Roger

只獲取name列:

SELECT name FROM people;
name
--------
Flavio
Roger

計算表中的項目數量:

SELECT COUNT(*) from people;
count
-------
2

您可以使用WHERE子句過濾表中的行:

SELECT age FROM people WHERE name='Flavio';
age
-----
37

查詢的結果可以按列值升序(默認)或降序使用ORDER BY進行排序:

SELECT * FROM people ORDER BY name;
SELECT * FROM people ORDER BY name DESC;