码迷,mamicode.com
首页 > 数据库 > 详细

mysql_3

时间:2015-11-08 14:01:05      阅读:293      评论:0      收藏:0      [点我收藏+]

标签:

日期查询:

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)
技术分享

 

mysql_3

标签:

原文地址:http://www.cnblogs.com/guxuanqing/p/4946356.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!