Summary of sql statement knowledge points

SQL
SQL is used to manage relational database management systems (RDBMS). The scope of SQL includes data insertion, query, update, and deletion, database schema creation and modification, and data access control.
SQL statement

select * from 表名;//搜索整个表
select * from 表名 where 列名=1;//搜索列名为1的数据
select 列名1,列名2 from 表名 where 列名=1;//搜索列名为1的数据,只显示列名1和列名2的数据
update 表名 set 列名1=10 where 列名=1;//修改列名为1的数据
delete from 表名 where 列名=1;//删除列名为1的数据
//修改和删除必须有指向的唯一性,不然会全部修改或删除
insert into 表名 (列名1,列名2) values ('数据','数据');//添加一条数据
select *from 表名 order by 列名 desc; //按照指定的排序,顺序(从小到大) asc(默认,可以不输入)﹔逆序(从大到小)desc
select distinct age from 表名;//去重根据年龄去重
select 别名.name , 别名.height from 表名 as 别名;//为表名取个别名,简便操作as:设置别名
select * from 表名 limit 2,1//限制查询的数据条数,第一个数字是起始位置,第二个数字是限制的行数
统计count(列名)sum(列名);平均数 avg(列名) ;最大值max(列名);最小值min(列名);
select * from 表名 where 列名 like '%%//模糊搜索,通过特定的值匹配到数据
select count(列名) from 表名;//通过年龄统计有多少条信息count()
select 列名 from 表名 groupby 列名;//分组去重
SELECT 表名1.列名1,表名1.列名2,表名2.列名1 FROM 表名1 INNER JOIN 表名2 ON 表名1.id = 表名2.id;//拼表内拼表inner join   右拼表right join   左拼表 left join 

Guess you like

Origin blog.csdn.net/Kenneth_JC/article/details/114540460