SQL Learning Note: functions

Source: Internet
Author: User

  • SQL functions
  • Avg
    Select AVG (col) as Avgvalue from TableName
    Select Col2 from tablename where col1> (select AVG (col1) from TableName)
  • COUNT return value does not contain a null value
    Select COUNT (*) from TableName Returns the number of rows
    Select COUNT (DISTINCT col) from TableName returns the unique value of the column
  • First returns a value
    Select First (col) as colname from TableName
  • Last return value
    Select Last (col) as colname from TableName
  • Max Returns the maximum value
  • Min returns the minimum value
  • Sum returns the sum
  • GROUP by
    Select col1, sum (col2) from TableName GROUP by col1
  • Having
    Select Custom, sum (price) from tablename where custom = ' Tom ' or the custom = ' Jerry ' GROUP by Custom has sum (price) >100 0
  • UCASE convert characters to uppercase
    Select UCASE (col) from TableName
  • LCASE character to lowercase
  • MID Extract Characters
    Select MID (col, starting number, length) from TableName
  • LEN Extract character length
  • ROUND rounding a specified number of digits
    Select ROUND (col, number of digits) from TableName
  • Now returns the current time and date
    Select Now () from TableName
  • FORMAT
    Select FORMAT (now (), ' Yyyy-mm-dd ') from TableName

SQL Learning Note: functions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.