文章目录
一切从创建数据库开始
数据库→基本表(创建-增删改查)→视图(创建-增删改查)
int #4个字节
smallint #2个字节
tinyint #1个字节
float #浮点型
numeric/decimal #小数
char #固定长度
varchar #可变长度
text #文本
datetime #8个字节
year #年
date #天
time #时间
create database 数据库名
default character set utf8;
alter database 数据库名;
drop database 数据库名;
定义
create table 表名
(
列名 数据类型 约束条件,
列名 数据类型 约束条件,
……
);
创建学生表student
唯一性标识 id:整型,自动增长列,主键
学号 sno:9个字符,非空,不允许重复
姓名 sname:20个字符,非空
性别 ssex:2个字符,男或女
年龄 sage:tinyint,15到45之间
系别 sdept:20个字符,默认值为计算机系
create table student
(
id int auto_increment primary key,
sno char(9) not null unique,
sname char(20) not null,
ssex char(2) check(ssex in ('男','女')),
sage smallint check(sage>=15 and sage<=45),
sdept char(20) default '计算机系'
);
创建课程表course
课程号 cno:4个字符 主键
课程名 cname: 50个可变长字符,不允许为空
先修课程号 cpno: 4个字符
学分 ccredit: smallint
先修课程号 cpno 参照 课程号cno 取值
create table course
(
cno char(4) primary key,
cname varchar(50) not null,
cpno char(4),
ccredit smallint,
foreign key(cpno) references course(cno)
);
创建成绩表sc
学号 sno:9个字符
课程号 cno:4个字符
成绩 grade: smallint
sno,cno:组合主键
sno参照student表的sno取值
cno参照course表的cno取值
create table sc
(
sno char(9) not null,
cno char(4) not null,
grade smallint,
primary key(sno,cno),
foreign key(sno) references student(sno),
foreign key(cno) references course(cno)
);
定义
alter table 表名 modify 列名 新数据类型 约束;
例:修改student的sdept为40个字符宽度
alter table student modify sdept char(40);
定义
alter table 表名 add 列名 数据类型 约束;
例:在student中增加address列
alter table student add address varchar(50) not null;
定义
alter table 表名 drop column 列名;
例:删除student的sage列
alter table student drop column sage;
定义
alter table 表名 add constraint 约束名 约束类型(列名);
例:在student中增加sno为主关键字
alter table student add primary key(sno);
例:添加sc的sno列的外码约束为student的sno
alter table sc add foreign key(sno) references studnet(sno);
定义
alter table 表名 drop 约束类型 约束名
例:删除student的主键约束
alter table student drop primary key
定义
drop table 表名
定义
select 查询目标
from 目标所在表
where 条件
group by 分组依据
having 分组条件
order by 排序依据
limit 限制;
select sno,sname from student;
select * from student;
select * from course;
select * from sc;
select sname as 'student name',2023-sage 'birthday' from student;
select sname
from student
where sdept='计算机系';
select sname
from student
where sage<20;
select sname
from student
where sage<20 and sdept='计算机系';
select sname,sage
from student
where sage>=22 and sage<=24;
select sname,sage
from student
where sage between 22 and 24;
select sname,ssex
from student
where sdept='信息系'
or sdept='数学系'
or sdept='计算机系';
select sname,ssex
from student
where sdept in ('信息系','数学系','计算机系');
select *
from student
where sdept is null;
select sno
from sc
where grade is null;
select sno,grade
from sc
where grade is not null;
select distinct sno
from sc;
select *
from student
where sname like "王%";
select *
from student
where sname like "%王%";
select *
from student
order by sage asc;
select sno,grade
from sc
where sno='c02'
order by grade desc;
select count(*)
from student
group by sno;
select count(distinct sno)
from sc
group by sno;
select sum(grade)
from sc
where sno='200215121'
group by sno;
select avg(grade)
from sc
where cno='c01'
group by cno ;
select max(sage)
from student
group by sno;
select cno,avg(grade)
from sc
group by cno;
select cno,count(*)
from sc
group by cno;
select sno,count(*),avg(grade)
from sc
group by sno;
select sno
from sc
group by sno
having count(*)>3;
select sno,avg(grade),count(*)
from sc
group by sno
having count(*)>=4;
select sno,count(*),avg(grade)
from sc
where grade>=60
group by sno
having count(*)>3 and avg(grade)>70
order by avg(grade) desc;
select student.sno,student.sname,avg(sc.grade) from student,sc
where student.sno=sc.sno
group by student.sno
order by avg(sc.grade)
limit 3;
select sno,group_concat(cno)
from sc
where sno='200215121';
select sno,group_concat(cno)
from sc
group by sno;
select student.sno,student.sname,count(sc.cno),
group_concat(cname order by cname separator ',')
from sc,student,course
where student.sno=sc.sno
and course.cno=sc.cno
group by student.sno
order by sno asc;
select student.sno,sname,ssex,sage,sdept,cno,grade
from student left join sc on student.sno=sc.sno;
select student.sname,sc.cno,sc.grade
from student,sc
where student.sno=sc.sno and sdept='计算机系';
select student.sname,course.cname,sc.grade
from student,course,sc
where student.sno=sc.sno
and course.cno=sc.cno
and sdept='计算机系';
select student.sname,course.cname
from student,course,sc
where student.sno=sc.sno
and course.cno=sc.cno
and sdept='计算机系';
select student.sno,student.sname,sc.cno,sc.grade from student,sc
where student.sno=sc.sno;
select student.sno,student.sname,sc.cno,sc.grade
from student
left join sc
on student.sno=sc.sno;
select a.cno,a.cname,b.cname
from course a,course b
where a.cpno=b.cno;
select *
from student
where sdept=
(select sdept from student where sname='刘晨')
and sname!='刘晨';
select *
from student
where sage=
(select min(sage) from student);
select *
from student
order by sage asc
limit 1;
select student.sno,student.sname
from student,sc
where student.sno=sc.sno and grade>90;
select sno,sname
from student
where sno in
(select sno from sc where grade>90);
select student.sno,student.sname,sc.grade
from student,sc
where student.sno=sc.sno and grade>90;
select sno,grade
from sc
where grade>
(select avg(grade) from sc where cno='c02' group by cno);
select a.sno,a.grade
from sc a
where grade>
(select avg(grade) from sc b
where a.cno=b.cno
group by b.cno);
select sno,cno,grade
from sc a
where grade>
(select avg(grade)
from sc b
where b.sno=a.sno);
select sname,sage
from student
where sdept!='信息系'and
sage<
(select max(sage)
from student
where sdept='信息系');
select sname,sage
from student
where sdept!='信息系' and
sage<
any(select age
from student
where sdept='信息系');
select sname
from student
where exists
(select * from sc where cno='c02' and sno=student.sno);
select sname from
student where sno in
(select sno from sc where cno='c02');
select sname from sc,student
where sc.sno=student.sno and sno='c02';
select sname from student
where not exists
(select * from sc where cno='c02' and sno=student.sno);
select sname
from student,sc
where student.sno=sc.sno and cno!='c02';
select sname
from student,sc,course
where student.sno=sc.sno and course.cno=sc.cno and cname='数据库';
select sname
from student
where exists
(select * from sc where cno=(select cno from course where cname='数据库'));
select sno from sc where cno='c01' and cno='c02';
select distinct sno
from sc where
sno in (select sno from sc where sno='c01') and
sno in (select sno from sc where sno='c02');
select distinct sno
from sc a
where exists
(select * from sc b where b.sno=a.sno
and cno='c01') and exists
(select * from sc c where c.sno=a.sno
and cno='c02');
select distinct sno from sc a where
exists(select * from sc b where b.sno=a.sno and
cno=(select cno from course where cname='数据库'))
and exists(select * from sc c where c.sno=a.sno and cno=(select cno from course where cname='数据结构'));
select sname from student
where not exists(select * from course
where not exists(select * from sc
where sno=student.sno and cno=course.cno);
select distinct sno from sc a
where not exists(select * from sc b
where sno='200215122' and
not exists(select * from sc c where
c.sno=a.sno and c.cno=b.cno);
(select sname as name from student)
union
(select cname from course);
定义
insert into 表名 (列名) values (值列表);
1. 将新生记录为(200821105,陈冬,男,18,信息系)插入到student表中
insert into student (sno,sname,ssex,sage,sdept)
values('200821105','陈冬','男',18,'信息系');
insert student
values('200821105','陈冬','男',18,'信息系');
2. 将与刘晨同一个系的新生记录(200821105,陈冬,男,18)插入到student表中
insert into student set sno='200821105',sname='陈冬',ssex='男',sage=18,
sdept=(select sdept from student where sname='刘晨');
3. 将新生记录(200821107,陈冬,男,18,信息系),(200821118,刘晨,男,18,信息系)一起插入到student表中
insert into student
values('200821107','陈冬','男',18,'信息系'),('200821108','刘晨','男',18,'信息系');
4. 在sc表中插入一新记录学号为200821105,课程为c01
insert into sc (sno,cno) values('200821105','c01',null);
insert into sc values('200821105','c01',null);
5. 备份c01的成绩到c01_cj新表中
create table c01_cj like sc;
insert into c01_cj
select * from sc where cno='c01';
定义
update 表名 set 列名=表达式 where 条件;
1. 将计算机系全体学生的成绩加5分
update sc set grade=grade+5
where sno in (select sno from student where sdept='计算机系');
2. 将平均成绩80分以上的学生成绩加3分
update sc set grade=grade+3
where sno in
(select sno from sc group by sno having avg(grade)>80);
3. 将数据结构3-5名学生的成绩加5分
update sc set grade=grade+5 where sno=
(select sno from course where course.cno=sc.cno and cname='数据结构'
order by grade desc limit 2,4);
定义
delete from 表名 where 条件;
1. 删除学号为200215121的学生的记录
delete from sc where sno='200215121';
delete from student where sno='200215121';
2. 删除所有学生的记录
delete from student;
3. 删除计算机系所有学生的选课记录
delete from sc where sno in(select sno from student where sdept='计算机系');
定义
create view 视图名 as 子查询;
1. 建立系名为计算机系的学生的视图
create view student_view as
select sno,sname,ssex,sdept from student
where sdept='计算机系';
2. 建立系名为计算机系的学生的视图,要求对视图的更新进行检查
create view student_view as
select sno,sname,ssex,sdept
from student
where sdept='计算机系'
with check option;
3. 建立信息系选修了c01课程的学生的视图
create view student_view as
select student.sno,student.sname,sc.grade
from student,sc
where student.sno=sc.sno
and sdept='信息系'
and cno='c01';
同基本表操作一样
数据库→基本表(创建-增删改查)→视图(创建-增删改查)
我主要使用Ruby来执行此操作,但到目前为止我的攻击计划如下:使用gemsrdf、rdf-rdfa和rdf-microdata或mida来解析给定任何URI的数据。我认为最好映射到像schema.org这样的统一模式,例如使用这个yaml文件,它试图描述数据词汇表和opengraph到schema.org之间的转换:#SchemaXtoschema.orgconversion#data-vocabularyDV:name:namestreet-address:streetAddressregion:addressRegionlocality:addressLocalityphoto:i
有时我需要处理键/值数据。我不喜欢使用数组,因为它们在大小上没有限制(很容易不小心添加超过2个项目,而且您最终需要稍后验证大小)。此外,0和1的索引变成了魔数(MagicNumber),并且在传达含义方面做得很差(“当我说0时,我的意思是head...”)。散列也不合适,因为可能会不小心添加额外的条目。我写了下面的类来解决这个问题:classPairattr_accessor:head,:taildefinitialize(h,t)@head,@tail=h,tendend它工作得很好并且解决了问题,但我很想知道:Ruby标准库是否已经带有这样一个类? 最佳
我正在尝试使用Curbgem执行以下POST以解析云curl-XPOST\-H"X-Parse-Application-Id:PARSE_APP_ID"\-H"X-Parse-REST-API-Key:PARSE_API_KEY"\-H"Content-Type:image/jpeg"\--data-binary'@myPicture.jpg'\https://api.parse.com/1/files/pic.jpg用这个:curl=Curl::Easy.new("https://api.parse.com/1/files/lion.jpg")curl.multipart_form_
无论您是想搭建桌面端、WEB端或者移动端APP应用,HOOPSPlatform组件都可以为您提供弹性的3D集成架构,同时,由工业领域3D技术专家组成的HOOPS技术团队也能为您提供技术支持服务。如果您的客户期望有一种在多个平台(桌面/WEB/APP,而且某些客户端是“瘦”客户端)快速、方便地将数据接入到3D应用系统的解决方案,并且当访问数据时,在各个平台上的性能和用户体验保持一致,HOOPSPlatform将帮助您完成。利用HOOPSPlatform,您可以开发在任何环境下的3D基础应用架构。HOOPSPlatform可以帮您打造3D创新型产品,HOOPSSDK包含的技术有:快速且准确的CAD
本教程将在Unity3D中混合Optitrack与数据手套的数据流,在人体运动的基础上,添加双手手指部分的运动。双手手背的角度仍由Optitrack提供,数据手套提供双手手指的角度。 01 客户端软件分别安装MotiveBody与MotionVenus并校准人体与数据手套。MotiveBodyMotionVenus数据手套使用、校准流程参照:https://gitee.com/foheart_1/foheart-h1-data-summary.git02 数据转发打开MotiveBody软件的Streaming,开始向Unity3D广播数据;MotionVenus中设置->选项选择Unit
文章目录一、概述简介原理模块二、配置Mysql使用版本环境要求1.操作系统2.mysql要求三、配置canal-server离线下载在线下载上传解压修改配置单机配置集群配置分库分表配置1.修改全局配置2.实例配置垂直分库水平分库3.修改group-instance.xml4.启动监听四、配置canal-adapter1修改启动配置2配置映射文件3启动ES数据同步查询所有订阅同步数据同步开关启动4.验证五、配置canal-admin一、概述简介canal是Alibaba旗下的一款开源项目,Java开发。基于数据库增量日志解析,提供增量数据订阅&消费。Git地址:https://github.co
我正在尝试在Rails上安装ruby,到目前为止一切都已安装,但是当我尝试使用rakedb:create创建数据库时,我收到一个奇怪的错误:dyld:lazysymbolbindingfailed:Symbolnotfound:_mysql_get_client_infoReferencedfrom:/Library/Ruby/Gems/1.8/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundleExpectedin:flatnamespacedyld:Symbolnotfound:_mysql_get_client_infoReferencedf
文章目录1.开发板选择*用到的资源2.串口通信(个人理解)3.代码分析(注释比较详细)1.主函数2.串口1配置3.串口2配置以及中断函数4.注意问题5.源码链接1.开发板选择我用的是STM32F103RCT6的板子,不过代码大概在F103系列的板子上都可以运行,我试过在野火103的霸道板上也可以,主要看一下串口对应的引脚一不一样就行了,不一样的就更改一下。*用到的资源keil5软件这里用到了两个串口资源,采集数据一个,串口通信一个,板子对应引脚如下:串口1,TX:PA9,RX:PA10串口2,TX:PA2,RX:PA32.串口通信(个人理解)我就从串口采集传感器数据这个过程说一下我自己的理解,
目录前言滤波电路科普主要分类实际情况单位的概念常用评价参数函数型滤波器简单分析滤波电路构成低通滤波器RC低通滤波器RL低通滤波器高通滤波器RC高通滤波器RL高通滤波器部分摘自《LC滤波器设计与制作》,侵权删。前言最近需要学习放大电路和滤波电路,但是由于只在之前做音乐频谱分析仪的时候简单了解过一点点运放,所以也是相当从零开始学习了。滤波电路科普主要分类滤波器:主要是从不同频率的成分中提取出特定频率的信号。有源滤波器:由RC元件与运算放大器组成的滤波器。可滤除某一次或多次谐波,最普通易于采用的无源滤波器结构是将电感与电容串联,可对主要次谐波(3、5、7)构成低阻抗旁路。无源滤波器:无源滤波器,又称
SPI接收数据左移一位问题目录SPI接收数据左移一位问题一、问题描述二、问题分析三、探究原理四、经验总结最近在工作在学习调试SPI的过程中遇到一个问题——接收数据整体向左移了一位(1bit)。SPI数据收发是数据交换,因此接收数据时从第二个字节开始才是有效数据,也就是数据整体向右移一个字节(1byte)。请教前辈之后也没有得到解决,通过在网上查阅前人经验终于解决问题,所以写一个避坑经验总结。实际背景:MCU与一款芯片使用spi通信,MCU作为主机,芯片作为从机。这款芯片采用的是它规定的六线SPI,多了两根线:RDY和INT,这样从机就可以主动请求主机给主机发送数据了。一、问题描述根据从机芯片手