SELECT
完整的分析语句语法如下:
SELECT [DISTINCT] (* | expression) [AS alias] [, ...] [GROUP BY expression [, ...] [HAVING predicates]] [ORDER BY expression [ASC | DESC] [, ...]] [LIMIT size OFFSET offset]
其中,SELECT表示指定查询的字段。本章节内容将介绍SELECT语法参数说明及示例。
使用*查询所有字段
SELECT *
account_number |
firstname |
gender |
city |
balance |
employer |
state |
lastname |
age |
---|---|---|---|---|---|---|---|---|
1 |
Amber |
M |
Brogan |
39225 |
Pyrami |
IL |
Duke |
32 |
16 |
Hattie |
M |
Dante |
5686 |
Netagy |
TN |
Bond |
36 |
13 |
Nanette |
F |
Nogal |
32838 |
Quility |
VA |
Bates |
28 |
18 |
Dale |
M |
Orick |
4180 |
null |
MD |
Adams |
32 |
查询指定字段
SELECT firstname, lastname
firstname |
lastname |
---|---|
Amber |
Duke |
Hattie |
Bond |
Nanette |
Bates |
Dale |
Adams |
使用AS给字段定义别名
SELECT account_number AS num
num |
---|
1 |
16 |
13 |
18 |
使用DISTINCT去重
SELECT DISTINCT age
age |
---|
32 |
36 |
28 |
使用SQL函数
函数相关内容请参见函数。
SELECT LENGTH(firstname) as len, firstname
len |
firstname |
---|---|
4 |
Amber |
6 |
Hattie |
7 |
Nanette |
4 |
Dale |