没有合适的资源?快使用搜索试试~ 我知道了~
Mysql实用知识库分享
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 157 浏览量
2023-11-10
18:06:18
上传
评论
收藏 3.66MB PDF 举报
温馨提示
试读
42页
资源Mysql实用知识库分享知识分享
资源推荐
资源详情
资源评论
MySQL
第1篇 MySQL查询数据(超详细)
MySQL查询数据(超详细)
一、简单查询语句
select * from 表名 条件查询语句;
二、多表查询
多张表有同名字段出现在select语句中,同名字段必须带上 “表名 . 字段名”
同名字段必须带上表名
如:
xxb1 xxb1 a cjb b a bselect .,, from , where .= .;
内连接:
1.使用=符号
2.使用inner join…on…
3.使用join…on…
如:
emp dept Dept_id dept idselect * from , where = . ;
emp dept Dept_id dept idselect * from join on = . ;
emp dept Dept_id dept idselect * from inner join on = . ;
自身连接:
一个表与其自己进行连接;需要给表起别名以示区别
如:
Qir cno Qir cname Qir cpno sec cname course Qir course sec Qir cpselect . , . , . , . from , where .
no sec cno= .
外连接:
可以左向外连接、右向外连接,外连接是以左边或右边的表作为主表,把主表的内容都显示,从
表没有的内容置为空处理
例如:主表 left join 表 ON a.no=b.no; 也可以换成left join
代码如下:
s sno sname sex age dept cno grade student s sc s snoselect . , , , , , , from left join ON .
sc sno= .
左连接:left join
:right join右连接
三、嵌套查询、子查询
:对数据来源的二次加工from使用子查询
如:
xxb1 a x cjb b a b xselect * from as ,(select max() as from ) as where .""= . ;
第1篇 MySQL查询数据(超详细)
第 1 页 /共
40 页
在where中使用子查询
如:
score score secre scoreselect * from where =(select max( ) from );
在select中使用子查询
如:
score score scoreselect (select count(*) from where <60)/(select count(*) from );
一般用于统计…率类的(如上班时间09:00后迟到的概率)
如:
kq substr notime kq(select count(*) from where ( ,12,5)>'09:00')/(select count(*) from )
;
嵌套查询
如:
select from where group by having order by
四、case语句
用法1:case 表达式
when 值1 then 返回值
when 值2 then 返回值
…
end
说明:end表示结束,也可以加上else ‘默认值’
如:
birselect no, ,
bir(case year( )
when '1998' then ''
when '1997' then ''
when '1996' then ''
else ''
end)
stufrom ;
用法2:case
when 表达式 运算符 值1 then 返回值1
when 表达式 运算符 值1 then 返回值2
…
else 返回值
end
如:
第1篇 MySQL查询数据(超详细)
第 2 页 /共
40 页
select
(case
bir when year( )>'1999' then ''
bir bir when year( )>='1995' and year ( )<='1999' then ''
bir bir when year ( )>='1990' and year ( )<'1995' then ''
else ''
xend) ,count(*)
stufrom
xgroup by ;
用嵌套查询的方法:
aselect .,count(*)
from(select
(case
result result when >=60 and <70 then '60~70'
result result when >=70 and <80 then '70~80'
result result when >=80 and <90 then '80~90'
result when >=90 then '90'
else ''
end)
grade afrom )
agroup by .;
第1篇 MySQL查询数据(超详细)
第 3 页 /共
40 页
剩余41页未读,继续阅读
资源评论
北极象
- 粉丝: 1w+
- 资源: 345
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功