SQL语句
- logical operators(逻辑运算符)
符号 | 举例 |
---|---|
and | where age >=30 and age <=40 |
or | where City = ‘New York’ or City =‘Chicago’ |
and…or | where City=‘New York’ and(Age=30 or Age=35) |
in | where City in (‘New York’ ,‘Los Angeles’) |
not in | where City not in (‘New York’ ,‘Los Angeles’) |
- CONTAT
把两个或多个表格属性用逗号连接起来,返回在一个列里。
select CONCAT(FirstName,',',City)
from customers
创建一个新的column
select CONCAT(FirstName,',',City) AS new_column
from customers
再次运行时列表名字将变成新定义的col
- Arithmetic Operators(算数符号)
加减乘除
ID | FirstName | LastName | Salary |
---|---|---|---|
1 | John | Smith | 2000 |
2 | David | Williams | 1500 |
select ID,FirstName,LastName,Salary+500 AS Salary
from employees
Result:
ID | FirstName | LastName | Salary |
---|---|---|---|
1 | John | Smith | 2500 |
2 | David | Williams | 2000 |
- UPPER(大写)、LOWER(小写)
select FirstName,UPPER(LastName) AS LastName
from employees
Results:
FirstName | LastName |
---|---|
John | SMITH |
David | WILLIAMS |