SQL 基础
SQL 简介
SQL 入门
SQL 语法
SQL 创建数据库
SQL 创建表
SQL Constraints
SQL Insert
SQL Select
SQL Where
SQL AND & OR
SQL IN & Between
SQL Order By
SQL Top/Limit
SQL Distinct
SQL Update
SQL Delete
SQL Truncate Table
SQL Drop
SQL 连接
SQL Joining Tables
SQL Inner Join
SQL Left Join
SQL Right Join
SQL Full Join
SQL Cross Join
高级 SQL
SQL Union
SQL Like
SQL Alter Table
SQL Aliases
SQL Group By
SQL Having
SQL Create View
SQL Create Index
SQL Dates and Times
SQL Cloning Tables
SQL 临时表
SQL 子查询
SQL 注入
SQL 参考
SQL 数据类型
MySQL 数据类型
SQL Server 数据类型
SQL 方法
SQL 方法 - SQL基础教程 - 笔下光年
网站首页
SQL 方法
SQL has many built-in functions that enable you to perform calculations on data. ## SQL Aggregate Functions SQL aggregate functions perform calculation on a set of values and return a single value. The following table summarizes some useful aggregate functions: | Function | Description | |----------|--------------------------------------------| | AVG() | Returns the average of values | | SUM() | Returns the sum of values | | COUNT() | Returns the number of rows in a result set | | MAX() | Returns the maximum value | | MIN() | Returns the minimum value | ## SQL String Functions SQL string functions perform operation on a string input value and return a string or numeric value. The following table summarizes some useful string functions: | Function | Description | |-------------|-----------------------| | CONCAT() | Returns a string by concatenating two or more string values. | | CONCAT_WS() | Returns a string by concatenating two or more string values with a separator. | | FORMAT() | Returns a value formatted with the specified format. | | LOWER() | Converts a string to lowercase. | | UPPER() | Converts a string to uppercase. | | TRIM() | Remove leading and trailing spaces from a string. | | REVERSE() | Returns the reverse order of a string value. | | SUBSTRING() | Returns a substring from string. | ## SQL Date Functions Date functions are used to manipulate or perform operation on date values. ### MySQL Date Functions The following table summarizes some most important MySQL's built-in date functions: | Function | Description | |---------------|-------------------------------------------------------------------| | NOW() | Returns the current date and time. | | CURDATE() | Returns the current date. | | CURTIME() | Returns the current time | | DATE() | Extract the date part of a date or datetime expression. | | DAY() | Returns the day of the month (0-31). | | DAYNAME() | Returns the name of the weekday. | | MONTH() | Returns the month from the date passed (1-12). | | MONTHNAME() | Returns the name of the month. | | YEAR() | Returns the year. | | DATE_FORMAT() | Displays date and time value in other formats. | | EXTRACT() | Extract part of a date. | | DATE_ADD() | Adds a specified time value (or interval) to a date value. | | DATE_SUB() | Subtracts a specified time value (or interval) from a date value. | | DATEDIFF() | Returns the number of days between two dates | <div class="callout callout-info mb-3">Note: The date and time returned by these functions is the date and time of the computer on which the instance of database server is running.</div> ### SQL Server Date Functions The following table summarizes some most important SQL Server's built-in date functions: | Function | Description | |------------|----------------------------| | GETDATE() | Returns the current date and time. | | DATEPART() | Returns the specified datepart of the specified date e.g. DATEPART(year,'2016-10-25') return 2016. | | DAY() | Returns the day of the month (0-31). | | MONTH() | Returns the month from the specified date (0-12). | | YEAR() | Returns the year from the specified date. | | DATEADD() | Adds or subtracts a specified time interval from a date. | | DATEDIFF() | Returns the date or time between two specified dates. | | CONVERT() | Displays date and time value in other formats. |
上一篇:
SQL Server 数据类型