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