首页 > 其他 > 详细

条件查询

时间:2021-06-18 11:42:33      阅读:17      评论:0      收藏:0      [点我收藏+]

create table student

(

  ID int primary key identity(1,1),

  studentNo varchar(20) not null,

  name varchar(20) not null,

  address varchar(20) not null,

  year int not null,

)

create table subject

(

  ID int primary key identity(1,1),

  subjectName varchar(20) not null,

  grade decimal(5,2) not null,  成绩

)

和(sum),最大(max),最小(min),where and(条件和),or(条件或) ,=等于,!=不等于

select max(grade )from student  查成绩和

select max(grade )from student  查最大成绩  
select avg(grade )from student  查平均数
select min(grade )from student  查最小成绩
select count(*)from student  查成绩总人数

select*from student ID>5 and ID!=6

select*from student ID=4 or ID>9

select top 2* from student  查询表前两条数据

select  top 2  ID from student  查询列名ID前两条数据

innert join 内连接,left join 左连接,right join 右连接

select* from student a inner join subject b on a.ID=b.ID

select* from student a left join subject b on a.ID=b.ID

select* from student a right join subject b on a.ID=b.ID

select (可以加查的列名,函数,条件等等) from student a right join subject b on a.ID=b.ID (后面可以加 where ID=ID之类的)

子查询两个案例

技术分享图片

 技术分享图片

条件查询

原文:https://www.cnblogs.com/howorld/p/14898375.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!