12、MySQL查询语句.pptVIP

  1. 1、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
  2. 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  3. 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
  4. 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
  5. 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们
  6. 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
  7. 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
12、MySQL查询语句.ppt

MySQL查询语句 查询语句的基本格式: select 列名1,列名2 from 表名 [where where_definition] [group by {unsigned_integer | col_name | formula} [ASC | DESC], ...] [having where_definition] [order by {unsigned_integer | col_name | formula} [| DESC] ,...] [limit [offset,] rows | rows OFFSET offset] ASC 说明: 1、查旬所有列:可用*来表示: select * from news_table; 2、[]中的为可选语句。 where 条件,用来筛选数据。 group by 用来分类汇总。 having :用来筛选分类汇总的结果。 order by用来排序。 limit用来取出指定的记录数。 根据sql查询表的个数,可以分为单表查询 和多表查询。 单表查询 测试数据,单表stu_info.sql 1、创建stu_info表 create table stu_info ( id int auto_increment, stu_num varchar(20), stu_name varchar(20), stu_sex char(2), stu_age int, stu_grade varchar(20), stu_class varchar(20), stu_subject varchar(20), stu_fee decimal(6,2), stu_time datetime, primary key(id) ); 字段说明如下: id,学号,姓名,性别,年龄,年级,班级,科目,分数,时间 2、查询所有数据 格式: select * from 表名; 例子: Select * from stu_info; 查询这个表的所有列(字段) Select id,stu_name from stu_info; 查询这个表的所有数据,只显示id和stu_name两个列。 指定别名: select id as ‘序号’ from stu_info; select id ‘序号’ from stu_info; select id as ‘序号’,stu_name as ‘姓名’ from stu_info; 指定别名,只是为了显示更加真观,并不真正改变表的列名。 3、where语句 where语句,后面可以跟着多个条件,从而来限制查询的数据。多个条件之间,可以用 and 或者 or 来链接。 例如: Select * from stu_info where id=5; Select * from stu_info where id5; Select * from stu_info where id=5; Select * from stu_info wehre id5; 分别表示: id为5的数据;id大于5的数据;Id小于或者等于5的数据;id不等于的数据; Select * from stu_info where id2 and stu_name=李婷婷‘ Select * from stu_info where id2 or stu_name=李婷婷‘ 用括号: select * from stu_info where stu_grade=09 and (stu_class=计算机2班 or stu_class=计算机3班); 4、order by语句 order by 用来指定数据的排序方式。有升序和降序两种。desc表示降序,asc为升序,默认为升序,asc可省略。 例如: select * from stu_info order by id asc; 按照id升序排序,其中asc可省略。 select * from stu_info order by id desc; 按照id降序 select * from stu_info where id=5 order by stu_time desc; 按时间降序 Order by 后台可指定多个排序字段,中间以逗号分隔。 例如: select * from stu_info order by stu_sex asc,stu_fee desc; 表示先按stu_sex(学生性别)升序排序,如果性别相同,再按学生成绩(stu_fee)降序排序。 order by 要写在where后面,limit前面。 5、g

文档评论(0)

czy2014 + 关注
实名认证
文档贡献者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档