1.查询整张表
select * from 表名;
2.查询表中的某几列
select 列名,列名 form 表名
3.查询时对某列进行计算并命名
select 列名*12 as "名字" from 表名
4.过滤重复的项目
select distinct 列名 from 表名
会过滤掉重复的null,也可以对多列的组合进行过滤
5.在某个范围之间查找
select * from 表名 where 条件 and/or 条件
6.查找属于诺干个孤立的值
select * from 表名 where 列名 in (xxx,xxx,xxx)
数据库中不等于的写法为
!= <>
7.查找最前面的几条记录
select top x * from 表名
percent表示百分比
8.查找null值
select * from 表名 where 列名 is null 查找为空的值 select * from 表名 where 列名 is not null 查找不为空的值
任何数值与空计算都为空
isnull(列名,0)表示将该列中的空值都按0计算
9.排序
order by 列名 desc/asc
desc表示降序,asc表示升序(默认即为升序,可不写)