SQL,如何使用SELECT
如何從SQL數據庫表中獲取數據
您可以使用SELECT
命令從表中獲取數據。
獲取所有行和列:
1 | SELECT * FROM people; |
1 | age | name |
只獲取name
列:
1 | SELECT name FROM people; |
1 | name |
計算表中的項目數量:
1 | SELECT COUNT(*) from people; |
1 | count |
您可以使用WHERE
子句過濾表中的行:
1 | SELECT age FROM people WHERE name='Flavio'; |
1 | age |
查詢的結果可以按列值升序(默認)或降序使用ORDER BY進行排序:
1 | SELECT * FROM people ORDER BY name; |
1 | SELECT * FROM people ORDER BY name DESC; |
tags: [“SQL”, “SELECT”, “WHERE”, “ORDER BY”]