标签:subject int lin cti 关键字 AC 英语 拼接 提交
create table scores(
id int primary key auto_increment,
stuid int,
subid int,
score decimal(5,2)
);
alter table scores add constraint stu_sco foreign key(stuid) references students(id);
create table scores(
id int primary key auto_increment,
stuid int,
subid int,
score decimal(5,2),
foreign key(stuid) references students(id),
foreign key(subid) references subjects(id)
);
alter table scores add constraint stu_sco foreign key(stuid) references students(id) on delete cascade;
create table areas(
id int primary key,
atitle varchar(20),
pid int,
foreign key(pid) references areas(id)
);
source areas.sql;
select city.* from areas as city
inner join areas as province on city.pid=province.id
where province.atitle=‘山西省‘;
select dis.*,dis2.* from areas as dis
inner join areas as city on city.id=dis.pid
left join areas as dis2 on dis.id=dis2.pid
where city.atitle=‘广州市‘;
select sname, (select sco.score from scores sco inner join subjects sub on sco.subid=sub.id where sub.stitle=‘语文‘ and stuid=stu.id) as 语文, (select sco.score from scores sco inner join subjects sub on sco.subid=sub.id where sub.stitle=‘数学‘ and stuid=stu.id) as 数学, (select sco.score from scores sco inner join subjects sub on sco.subid=sub.id where sub.stitle=‘英语‘ and stuid=stu.id) as 英语 from students stu;
select ascii(‘a‘);
select char(97);
select concat(12,34,‘ab‘);
select length(‘abc‘);
select substring(‘abc123‘,2,3);
select trim(‘ bar ‘);
select trim(leading ‘x‘ FROM ‘xxxbarxxx‘);
select trim(both ‘x‘ FROM ‘xxxbarxxx‘);
select trim(trailing ‘x‘ FROM ‘xxxbarxxx‘);
select space(10);
select replace(‘abc123‘,‘123‘,‘def‘);
select lower(‘aBcD‘);
select abs(-32);
select mod(10,3);
select 10%3;
select floor(2.3);
select ceiling(2.3);
select round(1.6);
select pow(2,3);
select PI();
select rand();
select year(‘2016-12-21‘);
select ‘2016-12-21‘+interval 1 day;
日期格式化date_format(date,format),format参数可用的值如下
获取年%Y,返回4位的整数
* 获取年%y,返回2位的整数
* 获取月%m,值为1-12的整数
获取日%d,返回整数
* 获取时%H,值为0-23的整数
* 获取时%h,值为1-12的整数
* 获取分%i,值为0-59的整数
* 获取秒%s,值为0-59的整数
select date_format(‘2016-12-21‘,‘%Y %m %d‘);
select current_date();
select current_time();
select now();
create view stuscore as
select students.*,scores.score from scores
inner join students on scores.stuid=students.id;
select * from stuscore;
show create table students;
alter table ‘表名‘ engine=innodb;
开启begin;
提交commit;
回滚rollback;
终端1:
select * from students;
------------------------
终端2:
begin;
insert into students(sname) values(‘张飞‘);
终端1:
select * from students;
终端2:
commit;
------------------------
终端1:
select * from students;
终端1:
select * from students;
------------------------
终端2:
begin;
insert into students(sname) values(‘张飞‘);
终端1:
select * from students;
终端2:
rollback;
------------------------
终端1:
select * from students;
标签:subject int lin cti 关键字 AC 英语 拼接 提交
原文地址:https://www.cnblogs.com/ghming/p/8969934.html