SQL003

Oracle查看表/查看限制/删除限制

创建表/增加数据

查看约束/删除约束/再增加数据

2019年3月18日星期一

数据库的数据类型:

数据约束关键字

说说primary key和unique区别?

 

数据库三范式

统计函数(聚合函数)

查询

 

找出需要补考的人,显示学号,补考课程号

统计姓张的男生人数

统计学号40和学号2的补考数量

统计男生的人数,显示性别 ,人数(写三种形式)

 

 

下列语句查询什么?

select   ssex  from   student   group by ssex

having  ssex=’m’  and   avg(sage)>=50  and count(*)>50;

统计总分在240以上的人,显示学号,总分,并按总分降序

   

 

统计门门及格且平均分在80以上的人,显示学号

 

                

统计平均成绩在60以上的人,显示学号,平均成绩

统计分数小于60的人数

 

统计分数小于60的人次

 

 

下列语句查询什么?

select  sid,count(*)  from  sc  where score<60 group by sid;

 

找出门门挂科的人,显示学号,挂科数量,并按挂科数量降序

找出同名的人,显示姓名,同名人数

 

     

统计每个人获得A等级(>=70)的数量 ,显示学号,等级、数量 并按照数量降序       

 

where和having的区别?

 

下列语句执行效果?

select  sid from  student  having  sid=1 or  sid=2  or sid=3;

 

实践:

以能下一个外卖订单为例,设计数据库,并创建数据库,增加数据

2019年3月19日星期二

 

 

多个数据源查询

 

数据源a

 

数据b

1

2

3

1

2

3

2

3

4

2

3

4

3

4

5

3

4

5

 

 

 

 

 

 

 

 

 

 

 

 

连接两个数据源select  *   from  a,b

 

 

 

 

 

 

 

1

2

3

1

2

3

1

2

3

2

3

4

1

2

3

2

3

4

2

3

4

1

2

3

2

3

4

2

3

4

2

3

4

3

4

5

3

4

5

1

2

3

3

4

5

2

3

4

3

4

5

3

4

5

 

 

 

select * from student a,student b;

select sid from student a,student b;

select a.* from student a,student ;

select student.* from student a,student ;

select a.sid,a.sname,b.sid,b.sname

from student a,student b;

 

 

查询同名的学生信息,显示学号,姓名,性别

数据源a

 

数据b

1

Zs

M

1

Zs

M

2

Ls

W

2

Ls

W

3

Zs

W

3

Zs

W

 

 

 

 

 

 

 

 

 

 

 

 

需要什么条件,才能将需要的数据连接起来

select * from  student a,student 

where  a.sid<>student.sid  and  a.sname=student.sname;

 

select  b.*from  student a,student   b

where  a.sid<>b.sid  and  a.sname=b.sname;

 

select a.sid,b.sname,a.ssex  from  student a,student   b

where  a.sid<>b.sid  and  a.sname=b.sname;

 

在一张空的学生信息表,增加2个张三,3个李四,5个潘涛

查询select a.sid,b.sname,a.ssex  from  student a,student   b

where  a.sid<>b.sid  and  a.sname=b.sname;

结果有(    )条数据

 

select sname,b.sid,cid,score from  student  a,  sc b;

 

select sname,b.sid,cid,score from  student  a,  sc b

where  a.sid=b.sid;

统计每个人的平均成绩,显示学号,姓名,平均成绩

select  a.sid,sname,avg(score) from  student  a,  sc b

where  a.sid=b.sid  group by a.sid; (   X   )

select  a.sid,sname,avg(score) from  student  a,  sc b

where  a.sid=b.sid  group by a.sid,sname;

select  a.sid,sname,avg(score) from  student  a,  sc b

where  a.sid=b.sid  group by a.sid,sname,ssex; ( 对 还是  错   )

 

统计每门课程的平均成绩,显示课程号(sc.cid  course.cid ),课程名称(course.cname),平均成绩(sc.score)

 

  from  sc  ,course  where sc.cid=course.cid

 

统计至少选修2门课程,且平均成绩在80以上的人,显示学号,姓名

 

 

 

下列语句查询什么?

select  a.sid,sname,avg(score) from student a ,sc

group by a.sid,sname;

 

不同count含义

SQL>create  table   testcnta(a  int  ,b  int);

a

b

1

 

1

1

 

1

2

3

                

SQL>select  count(*),count(a),count(b),count(distinct a) ,count(distinct b)  from  testcnta;

 

针对外卖系统表:

统计某天消费人数

统计某天消费人次

 

查询潘涛订的外卖,显示姓名,菜名,数量

统计潘涛2月花费总额,显示姓名,总额

统计每个人2月消费总额,并按总额降序,显示姓名,总额

   

   

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值