标签:
日期查询:
mysql> select * from member where birthday > ‘1962-01-01‘;
mysql> select * from member order by lastname desc,birthday asc;
+----+----------+-----------+--------+------------+-------+-----+
| id | lastname | firstname | status | birthday | score | sex |
+----+----------+-----------+--------+------------+-------+-----+
| 6 | z | y | | 0000-00-00 | 60 | 0 |
| 1 | james | john | s | 1972-01-01 | 60 | 1 |
| 5 | hash | newer | n | 1922-05-01 | 60 | 1 |
| 3 | hacker | johner | s | 1952-11-01 | 100 | 0 |
| 4 | busher | packer | s | 1962-01-01 | 0 | 1 |
| 2 | bush | pack | s | 1979-01-01 | 60 | 1 |
+----+----------+-----------+--------+------------+-------+-----+
6 rows in set (0.00 sec)
mysql> select * from member order by birthday asc limit 3;
+----+----------+-----------+--------+------------+-------+-----+
| id | lastname | firstname | status | birthday | score | sex |
+----+----------+-----------+--------+------------+-------+-----+
| 6 | z | y | | 0000-00-00 | 60 | 0 |
| 5 | hash | newer | n | 1922-05-01 | 60 | 1 |
| 3 | hacker | johner | s | 1952-11-01 | 100 | 0 |
+----+----------+-----------+--------+------------+-------+-----+
3 rows in set (0.01 sec)
mysql> select * from member order by birthday asc limit 2,3;
+----+----------+-----------+--------+------------+-------+-----+
| id | lastname | firstname | status | birthday | score | sex |
+----+----------+-----------+--------+------------+-------+-----+
| 3 | hacker | johner | s | 1952-11-01 | 100 | 0 |
| 4 | busher | packer | s | 1962-01-01 | 0 | 1 |
| 1 | james | john | s | 1972-01-01 | 60 | 1 |
+----+----------+-----------+--------+------------+-------+-----+
3 rows in set (0.01 sec)
随机输出限定数量(两个)结果:抽取幸运观众什么的
mysql> select * from member order by rand() limit 2;
mysql> select 17,format(sqrt(3*3+4*4),0);
+----+-------------------------+
| 17 | format(sqrt(3*3+4*4),0) |
+----+-------------------------+
| 17 | 5 |
+----+-------------------------+
1 row in set (0.00 sec)
合并输出:
mysql> select concat(firstname,‘ ‘,lastname) from member order by rand() asc limit 2;
+--------------------------------+
| concat(firstname,‘ ‘,lastname) |
+--------------------------------+
| pack bush |
| y z |
+--------------------------------+
2 rows in set (0.00 sec)
标签:
原文地址:http://www.cnblogs.com/guxuanqing/p/4946356.html