--把工资在1500到3000之间工资最高前四个人信息
select top 4 *
from emp
where sal between 1500 and 3000
order by sal desc --desc降序 不写则默认是升序
--输出奖金非空的员工信息
select * from emp where comm <> null; --输出为空 error
select * from emp where comm != null; --输出为空 error
select * from emp where comm = null; --输出为空 error
--总结 null不能参与<> != =运算
--null可以参与is not is
select * from emp where comm is null; --输出奖金为空的员工的信息
select * from emp where comm is not null; --输出奖金不为空的员工的信息
--任何类型的数据都允许为null
create table t1 (name nvarchar(20), cnt int, riqi datetime)
insert into t1 values(null,null,null)
select * from t1;
--输出每个员工的姓名 年薪(包含了奖金) comm假设是一年的奖金
select empno, ename,sal*12+comm "年薪"from emp;
--null 没有值 空值
零和null是不一样的 null表示空值 没有值 零表示一个确定的值
null 不能参与如下运算 <> != =
null可以参与如下运算 is not is
--任何类型数据都允许为null
create table t1 (name nvarchar(20), cnt int,riqi datetime);
insert into t1 values(null,null,null)
