Mysql 基础3
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Mysql 基础3,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2221字,纯文字阅读大概需要4分钟。
内容图文
![Mysql 基础3](/upload/InfoBanner/zyjiaocheng/1124/4397fb25415742c8a608b3a6ab53d74b.jpg)
查询 列 select.... from...
一 .简单查询 (查所有数据)
select*from表名 注: * 查所有的列
--------------------------------------------------------------------------------------
二.查询指定列的数据 (查询结果是虚拟的)
select 列名,列名from 表名
例子:select code,name from info;
三.修改结果集的列名
select code as ‘代号’,name as ‘姓名’ from info
----------------------------查询行-----------------------------------------------
四.出啊讯指定行的数据
select *form info where code=’p003’;
五 .多条件查询
查询 info表中 code为p003 或者 nation=‘n001’的
select *form info where code=’p003’ or nation=’n001’;
查询 info表中 code为p003 并且 nation=‘n001’的
select *form info where code=’p003’ and nation=’n001’;
六. 范围查询
select * from info where price>=40 and price<=70;
select * from info where price between 40 and 70;
------------------------------------------------------------------------in
七 . 离散查询
查询汽车价格(20,32,423,54,657,787)内的所有车
select *from info where price in(20,32,423,54,657,787);
查询汽车价格不在(20,32,423,54,657,787)内的所有车
select *from info where price not in(20,32,3,54,657,787);
-----------------------------------------------------------------------like
八. 模糊查询
查询表里的名称还有 奥迪的
select*from car where name like ‘%奥迪%’ % 表示任意n 个字符
查询汽车表中名称第二个字符为马的
select * from car where name like’_马’ _表示一个字符
九 .排序查询
价格升序排列
select*from car order by price asc asc升序 (可以省略)
价格降序排
select*from car order by price desc asc升序 (可以省略)
先按 brand 排列 再按 price 排列
select*from car order by brand,price,desc;
十. 去重查询
select distance brand from car;
十一;
一页显示10条 当前是 第 三页
select*from car limit 20,10
---------------------------------------------------------------------------------------------------------------------
十二. 聚合函数(统计函数)
select count(*) from chinastates #查询数据总条数
select count(areacode) from chinastates #查询数据总条数 括号呢 变成主键列 提高运行效率
select count(areacode) from chinastates #查询数据总条数 括号呢 变成主键列 提高运行效率
select sum(price) from car 求和
select ave(price) from car 平均值
select max(price) from car 最大
select min(price) from car 最小
---------------------------------group by.......having-------------------------------------------------------------
十三. 分组查询
查询汽车表中每个系列下有多少个汽车
select brand,count(*) from car group by brand ;
查询车店 卖的汽车数量大于4的
select brand from car group by brand having count(*)>3;
原文:http://www.cnblogs.com/ordinaryk/p/6124974.html
内容总结
以上是互联网集市为您收集整理的Mysql 基础3全部内容,希望文章能够帮你解决Mysql 基础3所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。