avg()函数
select avg(orderPrice) As OrderAverage from ordersspa
select customer from orders where orderPrice>(select avg(OrderPrice) from Orders)
code
count()orm
select count(column_name) from table_name
it
select count(distinct column_name) from table_name
table
select count(customer) as customerNilsen from orders where customer='Carter'
ast
select count(*) as numberofOrders from orders
form
select count(distinct customer) as numberofcustomers from orders
select
first()tab
first() 函数返回指定的字段中第一个记录的值。
select first(OrderPrice) As FirstOrderPrice from Orders
last()
LAST() 函数返回指定的字段中最后一个记录的值。
select last(OrderPrice) As LastOrderPrice from orders
max()
SELECT MAX(OrderPrice) AS LargestOrderPrice FROM Orders
min()
SELECT MIN(OrderPrice) AS SmallestOrderPrice FROM Orders
sum()
SELECT SUM(OrderPrice) AS OrderTotal FROM Orders
group by
SELECT Customer,SUM(OrderPrice) FROM Orders GROUP BY Customer
group by 一个以上的列
select Customer,OrderDate,SUM(OrderPrice) FROM Orders
group byCustomer,OrderDate
having子句
在 SQL 中增长 having 子句缘由是,where 关键字没法与合计函数一块儿使用
SELECT Customer,SUM(OrderPrice) FROM Orders GROUP BY Customer HAVING SUM(OrderPrice)<2000
SELECT Customer,SUM(OrderPrice) FROM Orders WHERE Customer='Bush' OR Customer='Adams' GROUP BY Customer HAVING SUM(OrderPrice)>1500
ucase()函数
ucase 函数把字段的值转换为大写。
SELECT UCASE(LastName) as LastName,FirstName FROM Persons
lcase() 函数
lcase() 函数把字段的值转换为小写。
SELECT LCASE(LastName) as LastName,FirstName FROM Persons
Mid() 函数
Mid 函数用于从文本字段中提取字符。
SELECT MID(City,1,3) as SmallCity FROM Persons
round() 函数
Round 函数用于把数值字段舍入为指定的小数位数。
SELECT ProductName, ROUND(UnitPrice,0) as UnitPrice FROM Products
Now() 函数
Now 函数返回当前的日期和时间。
SELECT ProductName, UnitPrice, Now() as PerDate FROM Products
format() 函数
format 函数用于对字段的显示进行格式化。
SELECT ProductName, UnitPrice, FORMAT(Now(),'YYYY-MM-DD') as PerDate FROM Products