1.SQL 命令
排序: select * from 表 where 条件 order by 字段 desc(降序)/asc(升序)
分组: group by 有一个原则,就是 select 后面的所有列中,没有使用聚合函数的列,必须出现在 group by 后面(重要)加条件用having
select 列,count(*) as num from 表 group by 列 having 条件
增加字段:alter table 表名 add 字段名 类型
删除字段:alter table 表名 drop column 字段名
修改类型:alter table 表名 alter column 列名 数据类型 (非空:not null /空:null)
insert into select: insert into 表A(字段1,字段2...)select 字段1,字段2... from 表B where 条件
case when:select case when isnull(列,'' )=='1' then '男' when isnull(列,'' )=='0' then '女' else '保密' end as 性别 from 表
with as 递归:https://www.cnblogs.com/wenyang-rio/p/3722868.html 实例网址(转载)
时间差:select datediff(day(返回的类型) ,开始时间,结束时间)