drop table if exists stu;
create table stu(
name varchar(30),
age int,
stuid int not null PRIMARY key AUTO_INCREMENT,
idnum int,
sex varchar(30),
check(sex in ('男','女'))
)charset=utf8;
insert into stu (name,age,idnum,sex)VALUES('damon',789,4678945,'男');
insert into stu (name,age,idnum,sex) VALUES('coco',13,345,'女');
insert into stu (name,age,idnum,sex)values('kitty',13,46,'女');
insert into stu (name,age,idnum,sex)values('alice',14,123,'女');
SELECT * from stu;
select * from stu limit 0,2;
select * from stu where name like '%ce';
select * from stu where name REGEXP "a[sfdl][^ads]";
select * from stu where name in ('damon','alice');
select * from stu where name BETWEEN 'coco' and 'kitty';
select * from stu where name not between 'coco' and 'kitty';
select name as stuname,stuid as id from stu;
drop view if EXISTS young_stu;
create view young_stu as
select name,age from stu where age between 10 and 20;
select * from young_stu where age is not null;
create table stu(
name varchar(30),
age int,
stuid int not null PRIMARY key AUTO_INCREMENT,
idnum int,
sex varchar(30),
check(sex in ('男','女'))
)charset=utf8;
insert into stu (name,age,idnum,sex)VALUES('damon',789,4678945,'男');
insert into stu (name,age,idnum,sex) VALUES('coco',13,345,'女');
insert into stu (name,age,idnum,sex)values('kitty',13,46,'女');
insert into stu (name,age,idnum,sex)values('alice',14,123,'女');
SELECT * from stu;
select * from stu limit 0,2;
select * from stu where name like '%ce';
select * from stu where name REGEXP "a[sfdl][^ads]";
select * from stu where name in ('damon','alice');
select * from stu where name BETWEEN 'coco' and 'kitty';
select * from stu where name not between 'coco' and 'kitty';
select name as stuname,stuid as id from stu;
drop view if EXISTS young_stu;
create view young_stu as
select name,age from stu where age between 10 and 20;
select * from young_stu where age is not null;
本文详细介绍了一个关于SQL中表的创建、数据插入及多种查询方式的实际案例,包括使用limit限制查询结果数量、like模糊匹配查询、正则表达式查询、in条件查询、between...and区间查询以及字段别名等技巧。
26万+

被折叠的 条评论
为什么被折叠?



