首页 > 其他 > 详细

查询语句格式

时间:2015-10-09 19:49:01      阅读:258      评论:0      收藏:0      [点我收藏+]
 1 SELECT [STRAIGHT_JOIN] [SQL_SMALL_RESULT] [SQL_BIG_RESULT] [HIGH_PRIORITY]  
 2 [DISTINCT | DISTINCTROW | ALL]  
 3 select_expression,...  
 4 [INTO {OUTFILE | DUMPFILE} ‘file_name‘ export_options]  
 5 [FROM table_references  
 6 [WHERE where_definition]  
 7 [GROUP BY col_name,...]  
 8 [HAVING where_definition]  
 9 [ORDER BY {unsigned_integer | col_name | formula} [ASC | DESC] ,...]  
10 [LIMIT [offset,] rows]  
11 [PROCEDURE procedure_name] ] 

1.查询所有数据:

select * from table;

2.查询行:

select * from table where (字段名1=‘xx’ and 字段名2!=‘xx‘ )  or 字段名3>100;

3.查询列:

select 字段1,字段2,字段3... from table;

4.查询排序行:

正序:select * from table order by 字段名1,字段名2;(可按多字段优先级排序)

倒序:select * from table order by 字段名1,字段名2 desc;(可按多字段优先级排序)

5.日期计算:(日期函数)

 1 插入一条记录:
 2 mysql> insert into user (id,name,nikename,sex,age,birth_date) values(1,yql,sunshine,1,28,1989-10-20 10:00:00)
 3 查看计算结果:to_days(now())天数
 4 mysql> select  name,(to_days(now())-to_days(birth_date))/365 as age1 from user;
 5 +------+---------+
 6 | name | age1    |
 7 +------+---------+
 8 | yql  | 26.9863 |
 9 +------+---------+
10 1 row in set (0.06 sec)

 

查询语句格式

原文:http://www.cnblogs.com/sunshine-habit/p/4864807.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!