Select * from websites where sal > 2000 and sal < 3000;
Select * from websites where sal between 2000 and 3000;
Select * from websites where sal in (5000,2000,3000);
Select * from websites where comm is null;
模糊查询:
% 表示多个字值,_ 下划线表示一个字符;
M% : 为能配符,正则表达式,表示的意思为模糊查询信息为 M 开头的。
%M% : 表示查询包含M的所有内容。
%M_ : 表示查询以M在倒数第二位的所有内容。
And 和 or
Select * from websites where country='CN' and alexa > 50;两个条件都成立时
Select * from websites where country='CN' or alexa >50;有一个条件成立时
Select * from websites where alexa > 15 and (country='CN' or country='USA');结合使用
Order by
Select * from websites order by country,alexa;
Order by a desc,b;
Insert
INSERT INTO table_name (column1,column2,column3,...) VALUES (value1,value2,value3,...);
Insert into websites (name, url, alexa, country) values ('百度','https://www.baidu.com/','4','CN');一般自动生成的id字段是不用指定的
insert into select 和select into from 的区别
insert into scorebak select * from socre where neza='neza' --插入一行,要求表scorebak 必须存在 select * into scorebak from score where neza='neza' --也是插入一行,要求表scorebak 不存在
Update
UPDATE table_name SET column1=value1,column2=value2,… WHERE some_column=some_value;
UPDATEWebsitesSETalexa='5000', country='USA' WHERE name='菜鸟教程';
没有where的字句会更新所有记录
Delete
DELETE FROM table_name WHERE some_column=some_value;