MySQL Date and time
*/
Get the current date and time
Mysql> Select Now ();
+---------------------+
| Now () |
+---------------------+
| 2015-10-28 19:51:17 |
+---------------------+
Get Current date
Mysql> select Curdate ();
+------------+
| Curdate () |
+------------+
| 2015-10-28 |
+------------+
Get current time
Mysql> select Curtime ();
+-----------+
| Curtime () |
+-----------+
| 19:57:01 |
+-----------+
DateTime () Gets the date and time
Date () Get dates
Time ()
Year ()
Month ()
Day () days
Hour ()
Minute () min
Second () seconds
All of these are interception formats like this
Mysql> Select year (' 20150303 ');
+------------------+
| Year (' 20150303 ') |
+------------------+
| 2015 |
+------------------+
Mysql> Select Date (' 20150303 ');
+------------------+
| Date (' 20150303 ') |
+------------------+
| 2015-03-03 |
+------------------+
/**
MySQL statistics and calculations (this is more important)
*/
Count how many data
Mysql> Select COUNT (*) from Stuinfo;
Get the minimum age value
Mysql> Select min (age) from Stuinfo;
Get maximum value with Max
Mysql> select Max (age) from Stuinfo;
Sum is obtained by sum ()
Mysql> select SUM (age) from Stuinfo;
Get average
Mysql> Select AVG (age) from Stuinfo;
All of these are group by ... that serve in groups ...
Group calculation of total number of male and female students
Mysql> Select Sex,count (*) from stuinfo GROUP by sex;
+------+----------+
| sex | COUNT (*) |
+------+----------+
| Male | 3 |
| Women | 3 |
+------+----------+
Having is used in conjunction with group by, and then adding group conditions after the combination is complete
Mysql> Select Sex,count (*) from Stuinfo GROUP by sex has sex= ' male ';
+------+----------+
| sex | COUNT (*) |
+------+----------+
| Male | 3 |
+------+----------+
MySQL first knowledge (v) Statistics and calculation and time