标签:rop c++ block 结果 mat table union sts 选择
*mysql -u root -p 密码
*create database Runoob(数据库名);
*drop database Runoob;
*use Runoob;
show databases;
create table Table_name charset=utf8;
create table if not exists ‘Table_name‘(
‘id‘ int unsigned primaty key auto_increment,
‘name‘ varchar(32) not null,
‘create_time‘ Date
)ENGING=InnoDB DEFAULT CHARSET=UTF8;
desc Table_name;
drop table Table_name;
show tables;
insert into Table_name (filed1,filed2,...) values (value1, value2,...);
实例:
insert into Table_name (‘name‘,‘create_time‘) values (‘学习mysql‘, NOW());
select column_name1, column_name2 from Table_name [where 条件] [limit n] [offset m]
1、通过limit属性限制返回的数量
2、通过offset指定开始查询的数据偏移量,默认是0
update Table_name set field1=new_value1,field2=new_value2 [where 条件]
根据条件修改指定某条数据某些字段的值
实例:
1、将所有人的年龄加1 update students set age=age+1;
2、将id为5的手机号改为默认的-:update students set tel=default where id=5;
3、将手机号为17521192856的姓名改为小马:update students set name=‘小马‘ where tel=‘17521192856‘;
update Table_name set filed_name=replace(field_name, ‘old_value‘,‘new_value‘) [where 条件]
实例:
把表中所有name列的值为c++的值改为python
update Table_name set name=replace(name, ‘c++‘, ‘python‘);
delete from Table_name [where 条件];
如果没有指定where子句,将删除表中的所有记录
实例:delete from students where id=3;
sql like 子句中使用%来表示任意字符,类似于正则表达式中的*,如果没有使用%,_表示一个占位字符,like子句与=的效果一样。
select field1,field2... from Table_name where field1 like 条件1 [and [or]] field2=‘somevalue‘;
实例:
1、查询name列中所有的包含COM的数据行
select * from students where name like ‘%COM‘;
select field1, field2,... from table1 [where 条件] union [all] select field11, field22,... from table2 [where 条件] [order by field]
标签:注:两个select语句中至少有一个field一样
实例:
select country from Websites union select country from apps order by country;去重
select country, name from Websites union all select country, app_name from apps order by country ASC;不去重
select field1,field2... from Table_name [where 条件] order by field1 desc;
内连接inner join ... on ...
table1:
table2:
从以上两张表来读取table1表中所有runoob_author字段在table2表对应的runoob_count字段值:
select a.runoob_id,a.runoob_author,b.runoob_count from table1 as a inner join table2 on a.runoob_author = b.runoob_author;
等同于:
select a.runoob_id,a.runoob_author,b.runoob_count from table1 as a, table2 as b where a.runoob_author = b.runoob_author;
左连接left join ... on ...(获取左侧表的所有数据和右侧满足条件的数据) :
select a.runoob_id,a.runoob_author,b.runoob_count from table1 as a left join table2 as b on a.runoob_author = b.runoob_author;
右连接:
select a.runoob_id, a.runoob_author,b.runoob_count from table1 as a right join table2 as b on a.runoob_author = b.runoob_author;
标签:rop c++ block 结果 mat table union sts 选择
原文地址:https://www.cnblogs.com/We612/p/10758055.html