常用sql
一.基础
create/drop database dbname / table tbname(新建/删除数据库、表)
alter table tbname add 字段名 类型
create index indexname on tbname(字段名) 创建索引
drop index indexname 删除索引
增删改查:
insert into tbname (字段a,字段b) values(a,b)
delete from tbname where id ='1'
update table set 字段= a where id=‘1’
select * from tbname
count,sum,avg,max,min
select distinct * from tbname order by id desc 去重复、倒序
筛选条件 where and ,having,group by,in,not in,not exists, select top 10 * from tbname,随机select newid(),order by newid()
多表查询
select * from tba a left join tbb b on a.id=b.id
right join on
select * from tba where a in (select * from tbb)