Operation when a select query is in MySQL

Source: Internet
Author: User

Select is the function of querying the data in a table in MySQL, but it can also be done directly at query time, and then return the result after the query.

Like what

1 SELECT user, Math*(Ifnull (Adven,0 from

The Ifnull function is to judge the Adven data, and if the data in Adven is not NULL, the data of the Adven itself is returned, and if NULL, 0 is returned.

Other +,-,/operations can also be replaced with the code above.

More functions

function Description
AVG (column) Returns the average of a column
COUNT (column) Returns the number of rows in a column (not including NULL values)
COUNT (*) Returns the number of rows selected
First (column) Returns the value of the first record in a specified field
Last (column) Returns the value of the last record in the specified field
MAX (column) Returns the highest value of a column
MIN (column) Returns the lowest value of a column
STDEV (column)
STDEVP (column)
SUM (column) Returns the sum of a column
VAR (column)
VARP (column)
GROUP by statement

The GROUP BY statement is used to combine aggregate functions to group result sets based on one or more columns.

We have the following "Orders" table:

o_id OrderDate Orderprice Customer
1 2008/12/29 1000 Bush
2 2008/11/23 1600 Carter
3 2008/10/05 700 Bush
4 2008/09/28 300 Bush
5 2008/08/06 2000 Adams
6 2008/07/21 100 Carter

Now we want to find the total amount (total order) for each customer.

We want to use GROUP by statements to group customers.

We use the following SQL statements:

1 SELECT Customer,SUM from Orders2GROUP by Customer

The result set looks like this:

Customer SUM (Orderprice)
Bush 2000
Carter 1700
Adams 2000

Operation when a select query is in MySQL

Related Article

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.