CREATEDATABASEtest;
usetest;
CREATETABLE student (
idint,
namevarchar(255),
address varchar(255),
city varchar(255)
);
INSERTINTO student VALUES (1, '刘一', '郑十家隔壁', '河南');
INSERTINTO student VALUES (2, '陈二', '李四家隔壁', '安徽');
INSERTINTO student VALUES (3, '张三', '白娘子家隔壁', '杭州');
INSERTINTO student VALUES (4, '李四', '许仙家隔壁', '杭州');
INSERTINTO student VALUES (5, '王五', '李四家隔壁', '杭州');
INSERTINTO student VALUES (6, '赵六', '赵六家隔壁', '杭州');
INSERTINTO student VALUES (7, '孙七', '张三家隔壁', '杭州');
INSERTINTO student VALUES (8, '周八', '雷峰塔附近', '杭州');
INSERTINTO student VALUES (9, '吴九', '孙七家隔壁', '杭州');
INSERTINTO student VALUES (10, '郑十', '周八家隔壁', '杭州');
SELECT * FROM student;
createdatabase a;
use a;
createtable q (
idint,
z varchar(255),
x varchar(255),
c varchar(255)
);
insertinto q values (1,'野人','神农架','湖北');
insertinto q values (2,'田鸡','畜生','鸡圈');
select *from q;
update q set c='h'where c='湖北';
select *from q;
deletefrom q whereid=1;
select * from q;
desc q;
select z,x from q;
CREATEdatabase b;
use b;
CREATETABLE Y(
NAMECHAR(3) ,
IDINT ,
XB CHAR(1),
cj int
);
desc Y;
insertinto Y values('赵三',1,'男',80);
insertinto Y (name,id,cj) values('李四',2,50);
insertinto Y(name,id,cj) values('王五',3,68);
insertinto Y setNAME = '赵六' , id = 4;
insertinto Y values('张三',7,'男',70);
insertinto Y values('张三',9,'男',40);
insertinto Y values('张三',65,'男',80);
select * from Y;
insertinto Y values('李华',5,'女',87);
select * from Y;
update Y set xb = '男'wherename = '李华';
update Y set cj = cj+10;
select * from Y;
deleteFROM Y whereid= 3;
select * FROM Y;
desc Y;
selectname ,cj FROM Y;
selectnameas 姓名,cj as'成 绩'FROM Y;
desc Y;
selectnameas 姓名,cj as 成绩 , casewhen cj>=90then'优秀'when cj >=80then'良好'else'差'endas 成绩 FROM Y;
selectnameas 姓名,cj as 成绩 , casewhen cj>=90then'优秀'when cj >=80then'良好'when cj >=70then'及格'else'差'endas 成绩评定 FROM Y;
selectnameas 姓名 ,cj+idas'总成绩'FROM Y;
selectdistinctnameas 姓名 from Y;
selectcount(*) as 总人数 FROM Y;
selectcount(cj) as 有成绩的人 FROM Y;
selectsum(cj) as 总成绩 FROM Y;
selectavg(cj) as 平均成绩 FROM Y;
selectmax(cj) as 最大值, min(cj) as 最小值 FROM Y;
selectvariance(cj) as 方差 FROM Y;
selectstddev(cj) as 标准差 FROM Y;
selectstd(cj) as 差 FROM Y ;
selectgroup_concat(name,cj) FROM Y where cj=90;
CREATETABLE y(
x int
);
insertinto y values(6);/*110*/insertinto y values(1);/*001*/selectbin(bit_and(x)) FROM y;/*只有有零就为零 000*/selectbin(bit_or(x)) FROM y;/*只要有一就为一 111*/selectbin(bit_xor(x)) FROM y;/*相同为零,不同为一 111*/