首页 技术 正文
技术 2022年11月10日
0 收藏 579 点赞 3,936 浏览 1042 个字

1简单查询   select* from 表名

select name as“姓名”fromstu     (把name改为名字)

2条件查询 where 后面跟条件  条件要写清楚

3模糊查询  like  no like    %代表任意多个字符   _代表一个字符

4排序查询  order by 字段 排序值 (desc降 asc升)

5范围查询     between….and…

6离散查询  in  notin

7聚合查询   sun 求和   count数据条数   max最大值  min最小值 avg平均值

8分页查询 limit 从第几条开始,取多少数据

表名limit(pagesize-1)*5,5     pagesize是页数   *5 是每页条数 ,5 取多少条

9去重查询 distinct      select distinct  表段名 from 表名

10分组查询 group by 字段  having 条件

select count(*),cno,group_concat(degree),sum(degree) from score group by cno ;

select cno,group_concat(degree),sum(degree) from score group by cno having count(*)>3

#分组之后根据条件查询使用having 不使用where

高级查询

  1. 连接查询,对列的扩展

Select * from student as stu,score as sc

where stu.sno = sc.sno and sc.sno = “103” ;

2.联合查询,对行的扩展

select Code,Name from Info

union

select Code,Name from Nation

3.子查询

(1)无关子查询

外层查询 (里层查询)

子查询的结果当做父查询的条件

子查询:select Code from Nation where Name=’汉族’

父查询:select * from Info where Nation = ”

select * from Info where Nation = (select Code from Nation where Name=’汉族’)

(2)相关子查询

查询汽车表中油耗低于该系列平均油耗的所有汽车信息

父查询:select * from Car where Oil<(该系列平均油耗)

子查询:select avg(Oil) from Car where Brand = ‘某个系列’

select * from Car a where Oil<(select avg(Oil) from Car b where b.Brand = a.Brand )

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,122
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,594
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,439
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,210
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,846
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,931